Created
July 17, 2020 02:21
-
-
Save jjergus/df568edd7cc02a39442217eb9861caf7 to your computer and use it in GitHub Desktop.
socket stuff
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
diff --git a/hphp/runtime/ext/hsl/ext_hsl_os.cpp b/hphp/runtime/ext/hsl/ext_hsl_os.cpp | |
index 9a20a4f1a2..19dba5ba6d 100644 | |
--- a/hphp/runtime/ext/hsl/ext_hsl_os.cpp | |
+++ b/hphp/runtime/ext/hsl/ext_hsl_os.cpp | |
@@ -389,9 +389,10 @@ struct HSLFileDescriptor { | |
return fd; | |
} | |
- void close() { | |
+ void close(bool sd) { | |
switch (m_type) { | |
case Type::FD: | |
+ if (sd) throw_errno_if_minus_one(::shutdown(fd(), SHUT_RDWR)); | |
throw_errno_if_minus_one(::close(fd())); | |
s_fds_to_close->erase(m_fd); | |
m_fd = -1; | |
@@ -582,8 +583,8 @@ int64_t HHVM_FUNCTION(HSL_os_write, const Object& obj, const String& data) { | |
return written; | |
} | |
-void HHVM_FUNCTION(HSL_os_close, const Object& obj) { | |
- HSLFileDescriptor::get(obj)->close(); | |
+void HHVM_FUNCTION(HSL_os_close, const Object& obj, int64_t sd) { | |
+ HSLFileDescriptor::get(obj)->close(sd != 0); | |
} | |
Array HHVM_FUNCTION(HSL_os_pipe) { | |
diff --git a/hphp/runtime/ext/hsl/ext_hsl_os.php b/hphp/runtime/ext/hsl/ext_hsl_os.php | |
index 506465508e..254efd1a45 100644 | |
--- a/hphp/runtime/ext/hsl/ext_hsl_os.php | |
+++ b/hphp/runtime/ext/hsl/ext_hsl_os.php | |
@@ -53,7 +53,7 @@ function read( | |
function write(FileDescriptor $fd, string $data): int; | |
<<__Native>> | |
-function close(FileDescriptor $fd): void; | |
+function close(FileDescriptor $fd, int $sd): void; | |
<<__Native>> | |
function pipe(): varray<FileDescriptor>; |
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
diff --git a/src/network/_Private/CancelablePoller.php b/src/network/_Private/CancelablePoller.php | |
index 9cc13c8..a974325 100644 | |
--- a/src/network/_Private/CancelablePoller.php | |
+++ b/src/network/_Private/CancelablePoller.php | |
@@ -37,9 +37,11 @@ final class CancelablePoller { | |
} | |
public function cancelAll(int $result): void { | |
+ /* | |
$ex = new PollCancelledException($result); | |
foreach ($this->polls as $poll) { | |
\HH\Asio\cancel($poll, $ex); | |
} | |
+ */ | |
} | |
} | |
diff --git a/src/network/_Private/socket_accept_async.php b/src/network/_Private/socket_accept_async.php | |
index c0a5005..fa1eb8e 100644 | |
--- a/src/network/_Private/socket_accept_async.php | |
+++ b/src/network/_Private/socket_accept_async.php | |
@@ -17,6 +17,7 @@ async function socket_accept_async( | |
OS\FileDescriptor $server, | |
CancelablePoller $poller, | |
): Awaitable<OS\FileDescriptor> { | |
+ //\var_dump($server); | |
try { | |
list($fd, $_addr) = OS\accept($server); | |
return $fd; | |
diff --git a/src/os/close.php b/src/os/close.php | |
index 249aeb0..7bfbe6b 100644 | |
--- a/src/os/close.php | |
+++ b/src/os/close.php | |
@@ -19,6 +19,6 @@ use namespace HH\Lib\_Private\_OS; | |
* This function is not automatically retried on `EINTR`, as `close()` is not | |
* safe to retry on `EINTR`. | |
*/ | |
-function close(FileDescriptor $fd): void { | |
- _OS\wrap_impl(() ==> _OS\close($fd)); | |
+function close(FileDescriptor $fd, bool $sd = false): void { | |
+ _OS\wrap_impl(() ==> _OS\close($fd, $sd ? 1 : 0)); | |
} | |
diff --git a/src/tcp/Server.php b/src/tcp/Server.php | |
index c900676..90a6d82 100644 | |
--- a/src/tcp/Server.php | |
+++ b/src/tcp/Server.php | |
@@ -126,7 +126,7 @@ final class Server implements Network\Server<CloseableSocket> { | |
} | |
public function stopListening(): void { | |
- OS\close($this->impl); | |
+ OS\close($this->impl, true); | |
$this->poller->cancelAll(\STREAM_AWAIT_CLOSED); | |
} | |
} | |
diff --git a/tests/tcp/HSLTCPTest.php b/tests/tcp/HSLTCPTest.php | |
index 40e7262..84b9c22 100644 | |
--- a/tests/tcp/HSLTCPTest.php | |
+++ b/tests/tcp/HSLTCPTest.php | |
@@ -199,6 +199,7 @@ final class HSLTCPTest extends HackTest { | |
$ex = expect(async () ==> await $accept_awaitable)->toThrow( | |
OS\ErrnoException::class, | |
); | |
- expect($ex->getErrno())->toEqual(OS\Errno::ECONNABORTED); | |
+ expect($ex->getErrno())//->toEqual(OS\Errno::ECONNABORTED); | |
+ ->toEqual(OS\Errno::EBADF); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment