version 1.4, 2005/03/06 22:17:33
|
version 1.8, 2005/03/08 00:10:38
|
|
|
return p - buf; | return p - buf; |
} | } |
| |
static int do_nonblocking_send ( int id, int first_time, SOCKET s, char *buf, int buflen, int sendlen ) |
|
{ |
|
char *last = buf + buflen; |
|
static char *p[MAX_CLIENTS]; |
|
int n; |
|
|
|
if ( first_time ) { |
|
p[id] = buf; |
|
} |
|
|
|
n = send ( s, p[id], min ( sendlen, last - p[id] ), 0 ); |
|
p[id] += n; |
|
|
|
return p[id] - buf; |
|
} |
|
|
|
static int do_nonblocking_recv ( int id, int first_time, SOCKET s, char *buf, int buflen, int recvlen ) |
|
{ |
|
char *last = buf + buflen; |
|
static char *p[MAX_CLIENTS]; |
|
int n; |
|
|
|
if ( first_time ) { |
|
p[id] = buf; |
|
} |
|
|
|
n = recv ( s, p[id], min ( recvlen, last - p[id] ), 0 ); |
|
p[id] += n; |
|
|
|
return p[id] - buf; |
|
} |
|
|
|
/* | /* |
* Call this routine right after thread startup. | * Call this routine right after thread startup. |
* SO_OPENTYPE must by 0, regardless what the server did. | * SO_OPENTYPE must by 0, regardless what the server did. |
|
|
FD_ZERO ( &fds_recv ); | FD_ZERO ( &fds_recv ); |
FD_ZERO ( &fds_send ); | FD_ZERO ( &fds_send ); |
FD_ZERO ( &fds_opensend ); | FD_ZERO ( &fds_opensend ); |
|
|
FD_SET ( mem->s, &fds_openrecv ); | FD_SET ( mem->s, &fds_openrecv ); |
| |
while(1) | while(1) |
|
|
| |
for ( i = 0; i < n_connections; i++ ) | for ( i = 0; i < n_connections; i++ ) |
{ | { |
if ( (mem->sock[i].n_recvd < n_expected) |
if ( FD_ISSET( mem->sock[i].s, &fds_recv ) ) { |
&& FD_ISSET( mem->sock[i].s, &fds_recv ) ) { |
|
| |
/* Receive data & check it */ | /* Receive data & check it */ |
mem->sock[i].n_recvd = do_nonblocking_recv ( i, (mem->sock[i].n_recvd == 0), mem->sock[i].s, mem->sock[i].buf, n_expected, par->buflen ); |
mem->sock[i].n_recvd += recv ( mem->sock[i].s, mem->sock[i].buf + mem->sock[i].n_recvd, min ( n_expected - mem->sock[i].n_recvd, par->buflen ), 0 ); |
| |
if ( mem->sock[i].n_recvd == n_expected ) { | if ( mem->sock[i].n_recvd == n_expected ) { |
p = test_buffer ( mem->sock[i].buf, gen->chunk_size, gen->n_chunks ); | p = test_buffer ( mem->sock[i].buf, gen->chunk_size, gen->n_chunks ); |
|
|
FD_CLR ( mem->sock[i].s, &fds_openrecv ); | FD_CLR ( mem->sock[i].s, &fds_openrecv ); |
} | } |
| |
} else if ( !FD_ISSET ( mem->sock[i].s, &fds_openrecv ) |
ok ( mem->sock[i].n_recvd <= n_expected, "select_server (%x): received too many bytes: %d\n", id, mem->sock[i].n_recvd ); |
&& FD_ISSET ( mem->sock[i].s, &fds_send ) ) { |
} |
|
|
|
if ( FD_ISSET ( mem->sock[i].s, &fds_send ) ) { |
|
|
/* Echo data back */ | /* Echo data back */ |
mem->sock[i].n_sent = do_nonblocking_send ( i, (mem->sock[i].n_sent == 0), mem->sock[i].s, mem->sock[i].buf, n_expected, par->buflen ); |
mem->sock[i].n_sent += send ( mem->sock[i].s, mem->sock[i].buf + mem->sock[i].n_sent, min ( n_expected - mem->sock[i].n_sent, par->buflen ), 0 ); |
| |
if ( mem->sock[i].n_sent == n_expected ) { | if ( mem->sock[i].n_sent == n_expected ) { |
FD_CLR ( mem->sock[i].s, &fds_opensend ); | FD_CLR ( mem->sock[i].s, &fds_opensend ); |
} | } |
} else if( FD_ISSET( mem->sock[i].s, &fds_recv ) ) { |
|
ok ( 0, "select_server (%x): too many bytes read\n", id ); |
ok ( mem->sock[i].n_sent <= n_expected, "select_server (%x): sent too many bytes: %d\n", id, mem->sock[i].n_sent ); |
} | } |
} | } |
| |
|
|
128 | 128 |
} | } |
}, | }, |
/* Test 2: event-driven client, non-blocking server via select() */ |
/* Test 2: synchronous client, non-blocking server via select() */ |
{ | { |
{ | { |
STD_STREAM_SOCKET, | STD_STREAM_SOCKET, |