version 1.3, 2005/03/06 21:46:38
|
version 1.4, 2005/03/06 22:17:33
|
|
|
struct sockaddr_in addr; | struct sockaddr_in addr; |
struct sockaddr_in peer; | struct sockaddr_in peer; |
char *buf; | char *buf; |
int nread; |
int n_recvd; |
|
int n_sent; |
} sock_info; | } sock_info; |
| |
/* Test parameters for both server & client */ | /* Test parameters for both server & client */ |
|
|
return p - buf; | return p - buf; |
} | } |
| |
static int do_nonblocking_send ( int id, SOCKET s, char *buf, int buflen, int sendlen ) |
static int do_nonblocking_send ( int id, int first_time, SOCKET s, char *buf, int buflen, int sendlen ) |
{ | { |
char* last = buf + buflen, *p; |
char *last = buf + buflen; |
int n = 1; |
static char *p[MAX_CLIENTS]; |
for ( p = buf; p < last; p += n ) |
|
n = send ( s, p, min ( sendlen, last - p ), 0 ); |
|
wsa_ok ( n, 0 <=, "do_synchronous_send (%lx): error %d\n" ); |
|
return p - buf; |
|
/* char *last = buf + buflen; |
|
static char *p[MAX_CLIENTS] = { NULL, NULL }; |
|
int n; | int n; |
| |
trace ( "id = %d\n", id ); |
if ( first_time ) { |
|
|
if ( p[id] == NULL ) { |
|
p[id] = buf; | p[id] = buf; |
} | } |
| |
n = send ( s, p[id], min ( sendlen, last - p[id] ), 0 ); | n = send ( s, p[id], min ( sendlen, last - p[id] ), 0 ); |
p[id] += n; | p[id] += n; |
| |
//wsa_ok ( n, 0 <=, "do_synchronous_send (%lx): error %d\n" ); |
return p[id] - buf; |
return p[id] - buf;*/ |
|
} | } |
| |
static int do_nonblocking_recv ( int id, SOCKET s, char *buf, int buflen, int recvlen ) |
static int do_nonblocking_recv ( int id, int first_time, SOCKET s, char *buf, int buflen, int recvlen ) |
{ | { |
char* last = buf + buflen, *p; |
char *last = buf + buflen; |
int n = 1; |
static char *p[MAX_CLIENTS]; |
for ( p = buf; p < last; p += n ) |
|
n = recv ( s, p, min ( recvlen, last - p ), 0 ); |
|
wsa_ok ( n, 0 <=, "do_synchronous_recv (%lx): error %d:\n" ); |
|
return p - buf; |
|
/* char *last = buf + buflen; |
|
static char *p[MAX_CLIENTS] = { NULL, NULL }; |
|
int n; | int n; |
| |
if ( p[id] == NULL ) { |
if ( first_time ) { |
p[id] = buf; | p[id] = buf; |
} | } |
| |
n = recv ( s, p[id], min ( recvlen, last - p[id] ), 0 ); | n = recv ( s, p[id], min ( recvlen, last - p[id] ), 0 ); |
p[id] += n; | p[id] += n; |
| |
//wsa_ok ( n, 0 <=, "do_synchronous_recv (%lx): error %d:\n" ); |
return p[id] - buf; |
return p[id] - buf;*/ |
|
} | } |
| |
/* | /* |
|
|
{ | { |
mem->sock[i].s = INVALID_SOCKET; | mem->sock[i].s = INVALID_SOCKET; |
mem->sock[i].buf = (LPVOID) LocalAlloc ( LPTR, gen->n_chunks * gen->chunk_size ); | mem->sock[i].buf = (LPVOID) LocalAlloc ( LPTR, gen->n_chunks * gen->chunk_size ); |
mem->sock[i].nread = 0; |
mem->sock[i].n_recvd = 0; |
|
mem->sock[i].n_sent = 0; |
} | } |
| |
if ( gen->sock_type == SOCK_STREAM ) | if ( gen->sock_type == SOCK_STREAM ) |
|
|
{ | { |
test_params *gen = par->general; | test_params *gen = par->general; |
server_memory *mem; | server_memory *mem; |
int n_recvd, n_sent, n_expected = gen->n_chunks * gen->chunk_size, tmp, i, |
int n_expected = gen->n_chunks * gen->chunk_size, tmp, i, |
id = GetCurrentThreadId(), n_connections = 0, done = 0; |
id = GetCurrentThreadId(), n_connections = 0; |
char *p; | char *p; |
struct timeval zerotime = {0,0}; | struct timeval zerotime = {0,0}; |
fd_set fds_recv, fds_send, fds_openrecv, fds_opensend; | fd_set fds_recv, fds_send, fds_openrecv, fds_opensend; |
|
|
| |
for ( i = 0; i < n_connections; i++ ) | for ( i = 0; i < n_connections; i++ ) |
{ | { |
if ( (mem->sock[i].nread < n_expected) |
if ( (mem->sock[i].n_recvd < n_expected) |
&& FD_ISSET( mem->sock[i].s, &fds_recv ) ) { | && FD_ISSET( mem->sock[i].s, &fds_recv ) ) { |
/* more data to receive */ |
|
| |
/* Receive data & check it */ | /* Receive data & check it */ |
n_recvd = do_nonblocking_recv ( i, mem->sock[i].s, mem->sock[i].buf, n_expected, par->buflen ); |
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 ); |
//ok ( n_recvd == n_expected, |
|
// "select_server (%x): received less data than expected: %d of %d\n", id, n_recvd, n_expected ); |
|
| |
if ( 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 ); |
ok ( p == NULL, "select_server (%x): test pattern error: %d\n", id, p - mem->sock[i].buf); | ok ( p == NULL, "select_server (%x): test pattern error: %d\n", id, p - mem->sock[i].buf); |
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 ) | } else if ( !FD_ISSET ( mem->sock[i].s, &fds_openrecv ) |
&& FD_ISSET ( mem->sock[i].s, &fds_send ) ) { | && FD_ISSET ( mem->sock[i].s, &fds_send ) ) { |
/* send data */ |
|
|
|
/* Echo data back */ | /* Echo data back */ |
n_sent = do_nonblocking_send ( i, mem->sock[i].s, mem->sock[i].buf, n_expected, par->buflen ); |
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 ); |
| |
//ok ( n_sent == n_expected, |
if ( mem->sock[i].n_sent == n_expected ) { |
// "select_server (%x): sent less data than expected: %d of %d\n", id, n_sent, n_expected ); |
|
|
|
if ( 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 ) ) { | } else if( FD_ISSET( mem->sock[i].s, &fds_recv ) ) { |
ok ( 0, "select_server (%x): too many bytes read\n", id ); | ok ( 0, "select_server (%x): too many bytes read\n", id ); |
} | } |
|
} |
| |
|
/* check if all clients are done */ |
if ( ( fds_opensend.fd_count == 0 ) | if ( ( fds_opensend.fd_count == 0 ) |
&& ( n_connections == min ( gen->n_clients, MAX_CLIENTS ) ) ) { | && ( n_connections == min ( gen->n_clients, MAX_CLIENTS ) ) ) { |
done = 1; |
|
break; |
|
} |
|
} |
|
|
|
if ( done == 1 ) { |
|
break; | break; |
} | } |
} | } |