| |
ntel corporation proprietary information copyright (c) 1995 intel corporation
this listing is supplied under the terms of a license agreement with intel corporation and may not be used, copied, nor disclosed except in accordance with the terms of that agreeement.
module name:
select.c
abstract:
this module contains the “select“ entry points from the winsock api. the following functions aare contained in this module.
select() wsaeventselect() wsaasyncselect() __wsafdisset()
author:
dirk brandewie dirk@mink.intel.com 14-06-1995
revision history:
22-aug-1995 dirk@mink.intel.com cleanup after code review. moved includes to precomp.h
16-aug-1995 dirk@mink.intel.com added implementation of __wsafdisset
--*/ #include “precomp.h“
int wsaapi select ( in int nfds, in out fd_set far *readfds, in out fd_set far *writefds, in out fd_set far *exceptfds, in const struct timeval far *timeout ) /*++ routine description:
determine the status of one or more sockets, waiting if necessary.
arguments:
nfds - this argument is ignored and included only for the sake of compatibility.
readfds - an optional pointer to a set of sockets to be checked for readability.
writefds - an optional pointer to a set of sockets to be checked for writability.
exceptfds - an optional pointer to a set of sockets to be checked for errors.
timeout - the maximum time for select() to wait, or null for blocking operation.
returns: select() returns the total number of descriptors which are ready and contained in the fd_set structures, 0 if the time limit expired, or socket_error if an error occurred. if the return value is socket_error, the error code is stored with setlasterror(). --*/ { int returnvalue; int errorcode; pdprovider provider; pdsocket socket; socket socketid; bool foundsocket=false;
errorcode = turbo_prolog();
if (errorcode == error_success) {
__try { // look for a socket in the three fd_sets handed in. the first // socket found will be used to select the service provider to // service this call if (readfds && readfds->fd_count) { socketid = readfds->fd_array[0]; foundsocket = true; } //if
if (!foundsocket && writefds && writefds->fd_count ) { socketid = writefds->fd_array[0]; foundsocket = true; } //if
if (!foundsocket && exceptfds && exceptfds->fd_count ) { socketid = exceptfds->fd_array[0]; foundsocket = true; } //if } __except (ws2_exception_filter()) { errorcode = wsaefault; goto returnerror; }
if (foundsocket) { socket = dsocket::getcounteddsocketfromsocket(socketid); if(socket != null){ provider = socket->getdprovider(); returnvalue = provider->wspselect( nfds, readfds, writefds, exceptfds, timeout, &errorcode); socket->dropdsocketreference(); if (returnvalue!=socket_error) return returnvalue;
assert (errorcode!=no_error); if (errorcode==no_error) errorcode = wsasyscallfailure;
} //if else { errorcode = wsaenotsock; } } //if else { errorcode = wsaeinval; } //else }
returnerror: setlasterror(errorcode); return(socket_error); } //select
int wsaapi wsaeventselect( in socket s, in wsaevent heventobject, in long lnetworkevents ) /*++ routine description:
specify an event object to be associated with the supplied set of fd_xxx network events.
arguments:
s - a descriptor identifying the socket.
heventobject - a handle identifying the event object to be associated with the supplied set of fd_xxx network events.
lnetworkevents - a bitmask which specifies the combination of fd_xxx network events in which the application has interest.
returns: zero on success else socket_error. the error code is stored with setlasterror(). --*/ { int returnvalue; int errorcode; pdprovider provider; pdsocket socket;
errorcode = turbo_prolog();
if (errorcode == error_success) { socket = dsocket::getcounteddsocketfromsocket(s); if(socket != null){ provider = socket->getdprovider(); returnvalue = provider->wspeventselect( s, heventobject, lnetworkevents, &errorcode); socket->dropdsocketreference(); if (returnvalue==error_success) return returnvalue; assert (errorcode!=no_error); if (errorcode==no_error) errorcode = wsasyscallfailure; } else { errorcode = wsaenotsock; } }
setlasterror(errorcode); return socket_error; } //wsaeventselect
int wsaapi wsaasyncselect( in socket s, in hwnd hwnd, in u_int wmsg, in long levent ) /*++ routine description:
request event notification for a socket.
arguments:
s - a descriptor identifying the socket for which event notification is required.
hwnd - a handle identifying the window which should receive a message when a network event occurs.
wmsg - the message to be received when a network event occurs.
levent - a bitmask which specifies a combination of network events in which the application is interested.
returns: the return value is 0 if the application‘s declaration of interest in the network event set was successful. otherwise the value socket_error is returned, and a specific error number may be retrieved by calling wsagetlasterror(). --*/ { int returnvalue; int errorcode; pdprovider provider; pdsocket socket;
errorcode = turbo_prolog();
if (errorcode == error_success) { socket = dsocket::getcounteddsocketfromsocket(s); if(socket != null){ provider = socket->getdprovider(); returnvalue = provider->wspasyncselect( s, hwnd, wmsg, levent, &errorcode); socket->dropdsocketreference(); if (returnvalue==error_success) return returnvalue; assert (errorcode!=no_error); if (errorcode==no_error) errorcode = wsasyscallfailure; } else { errorcode = wsaenotsock; } }
setlasterror(errorcode); return socket_error; } //wsaasyncselect
int far pascal __wsafdisset( socket fd, fd_set far *set) /*++ routine description:
determines if a specific socket is a contained in an fd_set.
arguments:
s - a descriptor identifying the socket.
set - a pointer to an fd_set. returns:
returns true if socket s is a member of set, otherwise false.
--*/ { int i = set->fd_count; // index into fd_set int rc=false; // user return code
while (i--){ if (set->fd_array[i] == fd) { rc = true; } //if } //while return (rc); } // __wsafdisset
int far pascal wpufdisset( socket fd, fd_set far *set) /*++ routine description:
determines if a specific socket is a contained in an fd_set.
arguments:
s - a descriptor identifying the socket.
set - a pointer to an fd_set. returns:
returns true if socket s is a member of set, otherwise false.
--*/ { int return_value;
return_value = __wsafdisset( fd, set ); return(return_value); } // wpufdisset
|
|