static void accept_it (rk_socket_t s, rk_socket_t *ret_socket) { rk_socket_t as; as = accept(s, NULL, NULL); if(rk_IS_BAD_SOCKET(as)) err (1, "accept"); if (ret_socket) { *ret_socket = as; } else { int fd = socket_to_fd(as, 0); /* We would use _O_RDONLY for the socket_to_fd() call for STDIN, but there are instances where we assume that STDIN is a r/w socket. */ dup2(fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO); rk_closesocket(as); } }
/* This function frees the socket before returning */ static int push_socket (Socket_Type *s) { SLFile_FD_Type *f; int status; if (s == NULL) return SLang_push_null (); if (NULL == (f = socket_to_fd (s))) { free_socket (s); return -1; } status = SLfile_push_fd (f); SLfile_free_fd (f); return status; }
int accept(int s, struct sockaddr* addr, socklen_t* addrlen) { return socket_to_fd(wrapSocketFunction<SOCKET>(::accept, s, addr, addrlen)); }
int socket(int af, int type, int protocol) { return socket_to_fd(::socket(af, type, protocol)); }