This repository has been archived by the owner on Dec 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 503
WIP: #776 - socket_recvfrom / socket_sendto support #780
Merged
sirsnyder
merged 11 commits into
krakjoe:master
from
sirsnyder:feature/776_socket_recvfrom_sendto
Jan 29, 2018
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
88eec0c
#776 - socket_recvfrom / socket_sendto support
sirsnyder 32756e4
Merge branch 'master' into feature/776_socket_recvfrom_sendto
sirsnyder 2284711
fixed implicit definition compiler warning
dktapps d091e37
Changes needed to get the extension to compile (krakjoe/pthreads#780)
dktapps 00f2b3f
fixing argcount check for sendto (krakjoe/pthreads#780)
dktapps d91f68b
Merge remote-tracking branch 'upstream/master' into feature/776_socke…
sirsnyder c022ac4
Fixed recvfrom/sendto using type instead of domain for switch
dktapps ff5c595
allow Socket->recvfrom() to accept null variables
dktapps 5ad6791
zend_string_free instead of efree
sirsnyder c64cbc6
Merge remote-tracking branch 'upstream/master' into feature/776_socke…
sirsnyder ec27fdd
Added some socket tests
sirsnyder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--TEST-- | ||
Test if socket_recvfrom() receives data sent by socket_sendto() via IPv4 UDP | ||
--CREDITS-- | ||
Copied from php/php-src and adjusted, originally created by | ||
Falko Menge <mail at falko-menge dot de> | ||
PHP Testfest Berlin 2009-05-09 | ||
--FILE-- | ||
<?php | ||
$socket = new Socket(\Socket::AF_INET, \Socket::SOCK_DGRAM, \Socket::SOL_UDP); | ||
if (!$socket) { | ||
die('Unable to create AF_INET socket'); | ||
} | ||
if (!$socket->setBlocking(false)) { | ||
die('Unable to set nonblocking mode for socket'); | ||
} | ||
|
||
$address = '127.0.0.1'; | ||
$socket->sendto('', 1, 0, $address); // cause warning | ||
if (!$socket->bind($address, 1223)) { | ||
die("Unable to bind to $address:1223"); | ||
} | ||
|
||
try { | ||
$socket->recvfrom($buf, 12, 0, $from, $port); | ||
} catch(RuntimeException $exception) { | ||
var_dump($exception->getMessage()); | ||
} | ||
$msg = "Ping!"; | ||
$len = strlen($msg); | ||
$bytes_sent = $socket->sendto($msg, $len, 0, $address, 1223); | ||
if ($bytes_sent == -1) { | ||
die('An error occurred while sending to the socket'); | ||
} else if ($bytes_sent != $len) { | ||
die($bytes_sent . ' bytes have been sent instead of the ' . $len . ' bytes expected'); | ||
} | ||
|
||
$from = ""; | ||
$port = 0; | ||
$socket->recvfrom($buf, 12, 0); // cause warning | ||
$socket->recvfrom($buf, 12, 0, $from); // cause warning | ||
$bytes_received = $socket->recvfrom($buf, 12, 0, $from, $port); | ||
if ($bytes_received == -1) { | ||
die('An error occurred while receiving from the socket'); | ||
} else if ($bytes_received != $len) { | ||
die($bytes_received . ' bytes have been received instead of the ' . $len . ' bytes expected'); | ||
} | ||
echo "Received $buf from remote address $from and remote port $port" . PHP_EOL; | ||
|
||
$socket->close(); | ||
--EXPECTF-- | ||
|
||
Warning: Wrong parameter count for Socket::sendto() in %s on line %d | ||
string(%d) "Error (%d): Resource temporarily unavailable" | ||
|
||
Warning: Socket::recvfrom() expects at least 4 parameters, 3 given in %s on line %d | ||
|
||
Warning: Wrong parameter count for Socket::recvfrom() in %s on line %d | ||
Received Ping! from remote address 127.0.0.1 and remote port 1223 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--TEST-- | ||
Test if socket_recvfrom() receives data sent by socket_sendto() via IPv6 UDP | ||
--CREDITS-- | ||
Copied from php/php-src and adjusted, originally created by | ||
Falko Menge <mail at falko-menge dot de> | ||
PHP Testfest Berlin 2009-05-09 | ||
--SKIPIF-- | ||
<?php | ||
if (substr(PHP_OS, 0, 3) == 'WIN') { | ||
die('skip Not valid for Windows'); | ||
} | ||
require 'assets/ipv6_skipif.inc'; | ||
--FILE-- | ||
<?php | ||
$socket = new Socket(\Socket::AF_INET6, \Socket::SOCK_DGRAM, \Socket::SOL_UDP); | ||
if (!$socket) { | ||
die('Unable to create AF_INET6 socket'); | ||
} | ||
if (!$socket->setBlocking(false)) { | ||
die('Unable to set nonblocking mode for socket'); | ||
} | ||
|
||
try { | ||
$socket->recvfrom($buf, 12, 0, $from, $port); | ||
} catch(RuntimeException $exception) { | ||
var_dump($exception->getMessage()); | ||
} | ||
$address = '::1'; | ||
$socket->sendto('', 1, 0, $address); // cause warning | ||
if (!$socket->bind($address, 1223)) { | ||
die("Unable to bind to $address:1223"); | ||
} | ||
|
||
$msg = "Ping!"; | ||
$len = strlen($msg); | ||
$bytes_sent = $socket->sendto($msg, $len, 0, $address, 1223); | ||
if ($bytes_sent == -1) { | ||
die('An error occurred while sending to the socket'); | ||
} else if ($bytes_sent != $len) { | ||
die($bytes_sent . ' bytes have been sent instead of the ' . $len . ' bytes expected'); | ||
} | ||
|
||
$from = ""; | ||
$port = 0; | ||
$socket->recvfrom($buf, 12, 0); // cause warning | ||
$socket->recvfrom($buf, 12, 0, $from); // cause warning | ||
$bytes_received = $socket->recvfrom($buf, 12, 0, $from, $port); | ||
if ($bytes_received == -1) { | ||
die('An error occurred while receiving from the socket'); | ||
} else if ($bytes_received != $len) { | ||
die($bytes_received . ' bytes have been received instead of the ' . $len . ' bytes expected'); | ||
} | ||
echo "Received $buf from remote address $from and remote port $port" . PHP_EOL; | ||
|
||
$socket->close(); | ||
--EXPECTF-- | ||
string(%d) "Error (%d): Resource temporarily unavailable" | ||
|
||
Warning: Wrong parameter count for Socket::sendto() in %s on line %d | ||
|
||
Warning: Socket::recvfrom() expects at least 4 parameters, 3 given in %s on line %d | ||
|
||
Warning: Wrong parameter count for Socket::recvfrom() in %s on line %d | ||
Received Ping! from remote address ::1 and remote port 1223 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is valid if compiled with
--enable-ipv6
. The AppVeyor configure options might need some adjustments.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you adjust AppVeyor to support IPV6?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I'll create a PR. Also, some of these tests aren't working correctly (see https://travis-ci.org/krakjoe/pthreads/jobs/334677874#L800)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like a travis issue travis-ci/travis-ci#8711
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the time being fixed with eaa0a58