mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
Make more fixes and improvements
- Remove PAGESIZE constant - Fix realloc() documentation - Fix ttyname_r() error reporting - Make forking more reliable on Windows - Make execvp() a few microseconds faster - Make system() a few microseconds faster - Tighten up the socket-related magic numbers - Loosen restrictions on mmap() offset alignment - Improve GetProgramExecutableName() with getenv("_") - Use mkstemp() as basis for mktemp(), tmpfile(), tmpfd() - Fix flakes in pthread_cancel_test, unix_test, fork_test - Fix recently introduced futex stack overflow regression - Let sockets be passed as stdio to subprocesses on Windows - Improve security of bind() on Windows w/ SO_EXCLUSIVEADDRUSE
This commit is contained in:
parent
140a8a52e5
commit
18bb5888e1
311 changed files with 1239 additions and 2622 deletions
|
@ -22,26 +22,31 @@
|
|||
#include "libc/sock/internal.h"
|
||||
#include "libc/sock/sock.h"
|
||||
#include "libc/sysv/consts/af.h"
|
||||
#include "libc/sysv/errfuns.h"
|
||||
|
||||
/**
|
||||
* Creates new system resource for network communication, e.g.
|
||||
*
|
||||
* int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
|
||||
*
|
||||
* @param family can be AF_UNIX, AF_INET, etc.
|
||||
* @param family can be AF_UNIX, AF_INET, AF_INET6, etc.
|
||||
* @param type can be SOCK_STREAM (for TCP), SOCK_DGRAM (e.g. UDP), or
|
||||
* SOCK_RAW (IP) so long as IP_HDRINCL was passed to setsockopt();
|
||||
* and additionally, may be or'd with SOCK_NONBLOCK, SOCK_CLOEXEC
|
||||
* @param protocol can be IPPROTO_TCP, IPPROTO_UDP, or IPPROTO_ICMP
|
||||
* @return socket file descriptor or -1 w/ errno
|
||||
* @error ENETDOWN, EPFNOSUPPORT, etc.
|
||||
* @raise EAFNOSUPPORT if `family` isn't supported by system or platform
|
||||
* @see libc/sysv/consts.sh
|
||||
* @asyncsignalsafe
|
||||
*/
|
||||
int socket(int family, int type, int protocol) {
|
||||
int rc;
|
||||
if (family == AF_UNSPEC) family = AF_INET;
|
||||
if (!IsWindows()) {
|
||||
if (family == AF_UNSPEC) {
|
||||
family = AF_INET;
|
||||
}
|
||||
if (family == -1) {
|
||||
rc = eafnosupport();
|
||||
} else if (!IsWindows()) {
|
||||
rc = sys_socket(family, type, protocol);
|
||||
} else {
|
||||
rc = sys_socket_nt(family, type, protocol);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue