Tchannel OS_server_connection_accept (Tchannel channel, void * peer_host, unsigned int * peer_port) { static struct sockaddr_in address; SOCKET s; { unsigned long nonblockp = (CHANNEL_NONBLOCKING (channel)); VOID_SOCKET_CALL (ioctlsocket, ((CHANNEL_SOCKET (channel)), FIONBIO, (&nonblockp))); } { int address_length = (sizeof (struct sockaddr_in)); s = (accept ((CHANNEL_SOCKET (channel)), ((struct sockaddr *) (&address)), (&address_length))); } if (s == INVALID_SOCKET) { DWORD code = (WSAGetLastError ()); if (code == WSAEWOULDBLOCK) return (NO_CHANNEL); NT_error_api_call (code, apicall_accept); } transaction_begin (); socket_close_on_abort (s); if (peer_host != 0) memcpy (peer_host, (& (address . sin_addr)), (sizeof (address . sin_addr))); if (peer_port != 0) (*peer_port) = (address . sin_port); RETURN_SOCKET (s, NT_channel_class_tcp_stream_socket); }
Tchannel OS_open_append_file (const char * filename) { HANDLE hFile; STD_HANDLE_API_CALL (hFile, CreateFile, (filename, GENERIC_WRITE, FILE_SHARE_READ /*sharing*/, 0, /*security*/ OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL /*attributes&flags*/, 0 /*Template*/ )); if ((SetFilePointer (hFile, 0, 0, FILE_END)) == 0xFFFFFFFF) NT_error_api_call ((GetLastError ()), apicall_SetFilePointer); return (NT_open_handle (hFile)); }
const char * OS_get_host_name (void) { unsigned int name_length = 128; char * name = (OS_malloc (name_length)); while (1) { if ((gethostname (name, name_length)) != SOCKET_ERROR) break; { DWORD code = (WSAGetLastError ()); if (code != WSAEFAULT) { OS_free (name); NT_error_api_call (code, apicall_gethostname); } } name_length *= 2; name = (OS_realloc (name, name_length)); } return (OS_realloc (name, ((strlen (name)) + 1))); }
static void socket_channel_close (Tchannel channel, int errorp) { if (((closesocket (CHANNEL_SOCKET (channel))) == SOCKET_ERROR) && errorp) NT_error_api_call ((GetLastError ()), apicall_closesocket); }