mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Introduce Socket.shutdown()
This commit is contained in:
@@ -155,3 +155,36 @@ fn void! Socket.close(&self) @inline @dynamic
|
||||
{
|
||||
self.sock.close()!;
|
||||
}
|
||||
|
||||
enum SocketShutdownHow
|
||||
{
|
||||
RECEIVE,
|
||||
SEND,
|
||||
BOTH,
|
||||
}
|
||||
|
||||
fn CInt SocketShutdownHow.os_value(self)
|
||||
{
|
||||
$switch
|
||||
$case env::WIN32:
|
||||
switch (self) {
|
||||
case RECEIVE: return libc::SD_RECEIVE;
|
||||
case SEND: return libc::SD_SEND;
|
||||
case BOTH: return libc::SD_BOTH;
|
||||
}
|
||||
$case env::POSIX:
|
||||
switch (self) {
|
||||
case RECEIVE: return libc::SHUT_RD;
|
||||
case SEND: return libc::SHUT_WR;
|
||||
case BOTH: return libc::SHUT_RDWR;
|
||||
}
|
||||
$default: $error("Unsupported environment");
|
||||
$endswitch
|
||||
}
|
||||
|
||||
fn void! Socket.shutdown(&self, SocketShutdownHow how)
|
||||
{
|
||||
if (libc::shutdown(self.sock, how.os_value()) < 0) {
|
||||
return os::socket_error()?;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user