(file) Return to sock.c CVS log (file) (dir) Up to [RizwankCVS] / wine4 / wine / dlls / winsock / tests

Diff for /wine4/wine/dlls/winsock/tests/sock.c between version 1.2 and 1.3

version 1.2, 2005/03/03 03:26:04 version 1.3, 2005/03/06 21:46:38
Line 2 
Line 2 
  * Unit test suite for winsock functions  * Unit test suite for winsock functions
  *  *
  * Copyright 2002 Martin Wilck  * Copyright 2002 Martin Wilck
    * select() server Copyright 2005 Thomas Kho
  *  *
  * This library is free software; you can redistribute it and/or  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public  * modify it under the terms of the GNU Lesser General Public
Line 202 
Line 203 
  
 static int do_nonblocking_send ( int id, SOCKET s, char *buf, int buflen, int sendlen ) static int do_nonblocking_send ( int id, SOCKET s, char *buf, int buflen, int sendlen )
 { {
     char *last = buf + buflen, *p[MAX_CLIENTS] = NULL;      char* last = buf + buflen, *p;
       int n = 1;
       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 ( p[id] == NULL ) {     if ( p[id] == NULL ) {
         p[id] = buf;         p[id] = buf;
     }     }
Line 213 
Line 223 
     p[id] += n;     p[id] += n;
  
     //wsa_ok ( n, 0 <=, "do_synchronous_send (%lx): error %d\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, SOCKET s, char *buf, int buflen, int recvlen )
 { {
     char *last = buf + buflen, *p[MAX_CLIENTS] = NULL;      char* last = buf + buflen, *p;
       int n = 1;
       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 ( p[id] == NULL ) {
Line 229 
Line 246 
     p[id] += n;     p[id] += n;
  
     //wsa_ok ( n, 0 <=, "do_synchronous_recv (%lx): error %d:\n" );     //wsa_ok ( n, 0 <=, "do_synchronous_recv (%lx): error %d:\n" );
     return p[id] - buf;      return p[id] - buf;*/
 } }
  
 /* /*
Line 412 
Line 429 
     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_recvd, n_sent, n_expected = gen->n_chunks * gen->chunk_size, tmp, i,
         id = GetCurrentThreadId(), n_connections = 0;          id = GetCurrentThreadId(), n_connections = 0, done = 0;
     char *p;     char *p;
     struct timeval zerotime = {0,0};     struct timeval zerotime = {0,0};
     fd_set fds_read, fds_write, fds_open;      fd_set fds_recv, fds_send, fds_openrecv, fds_opensend;
  
     trace ( "select_server (%x) starting\n", id );     trace ( "select_server (%x) starting\n", id );
  
Line 429 
Line 446 
     trace ( "select_server (%x) ready\n", id );     trace ( "select_server (%x) ready\n", id );
     SetEvent ( server_ready ); /* notify clients */     SetEvent ( server_ready ); /* notify clients */
  
     FD_ZERO ( &fds_openread );      FD_ZERO ( &fds_openrecv );
     FD_ZERO ( &fds_read );      FD_ZERO ( &fds_recv );
     FD_ZERO ( &fds_write );      FD_ZERO ( &fds_send );
       FD_ZERO ( &fds_opensend );
     FD_SET ( mem->s, &fds_open );      FD_SET ( mem->s, &fds_openrecv );
  
     while(1)     while(1)
     {     {
         fds_read = fds_write = fds_open;          fds_recv = fds_openrecv;
           fds_send = fds_opensend;
  
         select ( 0, &fds_read, &fds_write, NULL, &zerotime );          select ( 0, &fds_recv, &fds_send, NULL, &zerotime );
  
         /* check for incoming requests */         /* check for incoming requests */
         if ( FD_ISSET ( mem->s, &fds_read ) ) {          if ( FD_ISSET ( mem->s, &fds_recv ) ) {
             trace ( "select_server (%x): accepting client connection\n", id );             trace ( "select_server (%x): accepting client connection\n", id );
  
             /* accept a single connection */             /* accept a single connection */
Line 454 
Line 472 
                 "select_server (%x): strange peer address\n", id );                 "select_server (%x): strange peer address\n", id );
  
             /* add to list of open connections */             /* add to list of open connections */
             FD_SET ( mem->sock[i].s, &fds_open );              FD_SET ( mem->sock[i].s, &fds_openrecv );
               FD_SET ( mem->sock[i].s, &fds_opensend );
  
             n_connections += 1;              n_connections++;
         }         }
  
         /* handle open requests */         /* handle open requests */
Line 464 
Line 483 
         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].nread < n_expected)
                 && FD_ISSET( mem->sock[i].s, &fds_read ) ) {                  && FD_ISSET( mem->sock[i].s, &fds_recv ) ) {
                 /* more data to receive */                 /* more data to receive */
  
                 /* Receive data & check it */                 /* Receive data & check it */
                 n_recvd = do_nonblocking_recv ( i, mem->sock[0].s, mem->sock[0].buf, n_expected, par->buflen );                  n_recvd = do_nonblocking_recv ( i, mem->sock[i].s, mem->sock[i].buf, n_expected, par->buflen );
                 //ok ( n_recvd == n_expected,                 //ok ( n_recvd == n_expected,
                 //    "select_server (%x): received less data than expected: %d of %d\n", id, 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 ( n_recvd == n_expected ) {
                     p = test_buffer ( mem->sock[0].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[0].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 );
                 }                 }
  
             } else if ( mem->sock[i].nread == n_expected              } else if ( !FD_ISSET ( mem->sock[i].s, &fds_openrecv )
                 && FD_ISSET ( mem->sock[i].s, &fds_write ) ) {                  && FD_ISSET ( mem->sock[i].s, &fds_send ) ) {
                 /* send data */                 /* send data */
  
                 /* Echo data back */                 /* Echo data back */
                 n_sent = do_nonblocking_send ( i, mem->sock[0].s, mem->sock[0].buf, n_expected, par->buflen );                  n_sent = do_nonblocking_send ( i, mem->sock[i].s, mem->sock[i].buf, n_expected, par->buflen );
                 ok ( n_sent == n_expected,  
                     "select_server (%x): sent less data than expected: %d of %d\n", id, n_sent, n_expected );  
   
  
                   //ok ( n_sent == n_expected,
                   //    "select_server (%x): sent less data than expected: %d of %d\n", id, n_sent, n_expected );
  
             } else {                  if ( n_sent == n_expected ) {
                       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 ( 0, "select_server (%x): too many bytes read\n", id );
             }             }
   
               if ( ( fds_opensend.fd_count == 0 )
                   && ( n_connections  == min ( gen->n_clients, MAX_CLIENTS ) ) ) {
                   done = 1;
                                                                   break;
               }
           }
   
                                   if ( done == 1 ) {
                                           break;
         }         }
     }     }
  
Line 923 
Line 955 
             0,             0,
             64             64
         },         },
         event_client,          simple_client,
         {         {
             NULL,             NULL,
             WSA_FLAG_OVERLAPPED,              0,
             128             128
         }         }
     }     }


Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

Rizwan Kassim
Powered by
ViewCVS 0.9.2