| iMatix home page | << | < | > | >> |
![]() Version 2.11 |
#include "sflsock.h" sock_t accept_socket ( sock_t master_socket)
Accepts a connection on a specified master socket. If you do not want to wait on this call, use select() to poll the socket until there is an incoming request, then call accept_socket. Returns the number of the new slave socket, or INVALID_SOCKET if there was an error on the accept call. You can handle errors as fatal except for EAGAIN which indicates that the operation would cause a non-blocking socket to block (treat EWOULDBLOCK in the same way).
{ #if (defined (DOES_SOCKETS)) sock_t slave_socket; /* Connected slave socket */ struct sockaddr_in sin; /* Address of connecting party */ argsize_t sin_length; /* Length of address */ connect_error_value = IP_NOERROR; /* Assume no errors */ sin_length = (int) sizeof (sin); slave_socket = accept ((SOCKET) master_socket, (struct sockaddr *) &sin, &sin_length); /* On non-Windows systems, accept returns -1 in case of error, which */ /* is the same as INVALID_SOCKET. */ # if (defined (__WINDOWS__)) if (slave_socket == INVALID_SOCKET) { int sock_errno = WSAGetLastError (); if (sock_errno == WSAEWOULDBLOCK || sock_errno == WSAEINPROGRESS) errno = EAGAIN; } # endif if (slave_socket != INVALID_SOCKET) { prepare_socket (slave_socket); ip_sockets++; } return (slave_socket); #else connect_error_value = IP_NOSOCKETS; return (INVALID_SOCKET); /* Sockets not supported */ #endif }
| << | < | > | >> |
![]() |