generated from alii/ts-npm-template
-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
67 additions
and
13 deletions.
There are no files selected for viewing
Binary file not shown.
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,33 @@ | ||
module socket | ||
|
||
$if !windows { | ||
#include <sys/socket.h> | ||
} | ||
|
||
// read_socket reads from a socket into a buffer | ||
@[inline] | ||
pub fn read_socket(fd int, buffer &u8, max_len int, offset int) int { | ||
// use `recv` instead of `read` for windows compatibility | ||
return unsafe { C.recv(fd, buffer + offset, max_len - offset, 0) } | ||
} | ||
|
||
// is_fatal_error returns true if the socket error is fatal | ||
@[inline] | ||
pub fn is_fatal_error(fd int) bool { | ||
if C.errno == C.EAGAIN { | ||
// try again later | ||
return false | ||
} | ||
$if windows { | ||
if C.errno == C.WSAEWOULDBLOCK { | ||
// try again later | ||
return false | ||
} | ||
} $else { | ||
if C.errno == C.EWOULDBLOCK { | ||
// try again later | ||
return false | ||
} | ||
} | ||
return true | ||
} |