[netperf-talk] MingW/gcc patches

Rick Jones rick.jones2 at hp.com
Wed Feb 14 13:34:53 PST 2007


Gisle Vanem wrote:
> As promised, here are some patches to be able to build using
> the superiour MingW + gcc combination on Windows. The diff-1.txt 
> contains several patches:
> 
> * netlib.c: gcc uses 'LL' suffix for unsigned long long types.  MSVC 
> uses 'i64'.
> 
> * netlib.c: Fix call to 'GetComputerName()'. (who ever got this through?).
> 
> * nettest_bsd.c: Added 'remote_res' and 'local_res'. Winsock never sets
>  'EAGAIN'. 'unsigned_short' replaced with 'unsigned short' (a typo?).
> 
> * netlib.[ch]: Added a function 'set_nonblock()' for the simple task
>  of setting a socket to non-blocking mode. Use it in nettest_bsd.c,
>  nettest_ipv6.c and nettest_sctp.c

FWIW, that nettest_ipv6.c still appears in the repository is only a 
function of my forgetfulness and fear uncertainty and doubt of proper 
SVN commands - the IPv6 functionalit has been subsumed into the 
nettest_bsd.c tests so there is no need to do anything with 
nettest_ipv6.c.  I've updated the makefiles to not include it in a 
source tar/zip but still have to remove it from top of trunk in the 
repository.

> And yes, Rick, I did have the latest trunk (check the time-stamp of 
> netlib.c).

:)

> Patch attached.
> 
> --gv
> diff -u3 -Hb -r SVN-Latest/src/netlib.c netlib.c
> --- SVN-Latest/src/netlib.c    Wed Feb 14 14:25:53 2007
> +++ netlib.c    Wed Feb 14 14:29:37 2007
> @@ -687,10 +687,16 @@
> }
> 
> #ifdef WIN32
> +#ifdef __GNUC__
> +  #define S64_SUFFIX(x) x##LL
> +#else
> +  #define S64_SUFFIX(x) x##i64
> +#endif
> +
> /*
>  * Number of 100 nanosecond units from 1/1/1601 to 1/1/1970
>  */
> -#define EPOCH_BIAS  116444736000000000i64
> +#define EPOCH_BIAS  S64_SUFFIX(116444736000000000)
> 
> /*
>  * Union to facilitate converting from FILETIME to unsigned __int64
> @@ -708,9 +714,9 @@
> 
>         GetSystemTimeAsFileTime( &(nt_time.ft_struct) );
> 
> -        UnixTime = ((nt_time.ft_scalar - EPOCH_BIAS) / 10i64);
> -        tv->tv_sec = (long)(time_t)(UnixTime / 1000000i64);
> -        tv->tv_usec = (unsigned long)(UnixTime % 1000000i64);
> +        UnixTime = ((nt_time.ft_scalar - EPOCH_BIAS) / S64_SUFFIX(10));
> +        tv->tv_sec = (long)(time_t)(UnixTime / S64_SUFFIX(1000000));
> +        tv->tv_usec = (unsigned long)(UnixTime % S64_SUFFIX(1000000));
> }
> #endif /* WIN32 */
> 
> @@ -1982,6 +1988,21 @@
> }
> 
> 
> +/*
> + * Sets a socket to non-blocking operation.
> + */
> +int
> +set_nonblock (SOCKET sock)
> +{
> +#ifdef WIN32
> +  unsigned long flags = 1;
> +  return (ioctlsocket(sock, FIONBIO, &flags) != SOCKET_ERROR);
> +#else
> +  return (fcntl(sock, F_SETFL, O_NONBLOCK) != -1);
> +#endif
> +}
> +
> +
> 
>  /***********************************************************************/
>  /*                                                                     */
> @@ -2765,7 +2786,7 @@
>     static char id_string[80];
> #ifdef WIN32
> char                    system_name[MAX_COMPUTERNAME_LENGTH+1] ;
> -int                     name_len = MAX_COMPUTERNAME_LENGTH + 1 ;
> +DWORD                   name_len = MAX_COMPUTERNAME_LENGTH + 1 ;
> #else
> struct  utsname         system_name;
> #endif /* WIN32 */
> @@ -2773,7 +2794,7 @@
> #ifdef WIN32
>  SYSTEM_INFO SystemInfo;
>  GetSystemInfo( &SystemInfo ) ;
> - if ( !GetComputerName(system_name , &(DWORD)name_len) )
> + if ( !GetComputerName(system_name , &name_len) )
>    strcpy(system_name , "no_name") ;
> #else
>  if (uname(&system_name) <0) {
> diff -u3 -Hb -r SVN-Latest/src/netlib.h netlib.h
> --- SVN-Latest/src/netlib.h    Wed Feb 14 14:25:53 2007
> +++ netlib.h    Wed Feb 14 14:30:11 2007
> @@ -478,6 +478,8 @@
> extern  float   calibrate_local_cpu(float local_cpu_rate);
> extern  float   calibrate_remote_cpu();
> extern  void    bind_to_specific_processor(int processor_affinity,int 
> use_cpu_map);
> +extern int      set_nonblock (SOCKET sock);
> +
> #ifndef WIN32
> 
> /* WIN32 requires that at least one of the file sets to select be
> diff -u3 -Hb -r SVN-Latest/src/nettest_bsd.c nettest_bsd.c
> --- SVN-Latest/src/nettest_bsd.c    Sun Feb 11 15:53:55 2007
> +++ nettest_bsd.c    Tue Feb 13 17:13:38 2007
> @@ -10070,6 +10070,9 @@
>   struct    tcp_rr_response_struct    *tcp_rr_response;
>   struct    tcp_rr_results_struct    *tcp_rr_result;
> 
> +  struct addrinfo *remote_res;
> +  struct addrinfo *local_res;
> +
>   tcp_rr_request =
>     (struct tcp_rr_request_struct 
> *)netperf_request.content.test_specific_data;
>   tcp_rr_response=
> @@ -10251,8 +10254,8 @@
>     }
> 
>     /* now that we are connected, mark the socket as non-blocking */
> -    if (fcntl(send_socket, F_SETFL, O_NONBLOCK) == -1) {
> -      perror("netperf: fcntl");
> +    if (!set_nonblock(send_socket) {
> +      perror("netperf: set_nonblock");
>       exit(1);
>     }
> 
> @@ -10341,10 +10344,12 @@
>         timed_out = 1;
>         break;
>       }
> +#ifndef WIN32
>       else if (errno == EAGAIN) {
>         Set_errno(0);
>         continue;
>       }
> +#endif
>       else {
>         perror("send_tcp_nbrr: data recv error");
>         exit(1);
> @@ -10723,7 +10728,7 @@
>     sizeof(myaddr_in));
>   myaddr_in.sin_family      = AF_INET;
>   myaddr_in.sin_addr.s_addr = INADDR_ANY;
> -  myaddr_in.sin_port        = htons((unsigned_short)tcp_rr_request->port);
> +  myaddr_in.sin_port        = htons((unsigned short)tcp_rr_request->port);
> 
>   /* Grab a socket to listen on, and then listen on it. */
> 
> @@ -10857,7 +10862,7 @@
> #endif /* KLUDGE_SOCKET_OPTIONS */
> 
>   /* now that we are connected, mark the socket as non-blocking */
> -  if (fcntl(s_data, F_SETFL, O_NONBLOCK) == -1) {
> +  if (!set_nonblock(s_data)) {
>     close(s_data);
>     exit(1);
>   }
> diff -u3 -Hb -r SVN-Latest/src/nettest_ipv6.c nettest_ipv6.c
> --- SVN-Latest/src/nettest_ipv6.c    Sun Feb 11 15:53:56 2007
> +++ nettest_ipv6.c    Tue Feb 13 17:15:51 2007
> @@ -6739,8 +6739,8 @@
>     }
> 
>     /* now that we are connected, mark the socket as non-blocking */
> -    if (fcntl(send_socket, F_SETFL, O_NONBLOCK) == -1) {
> -      perror("netperf: fcntl");
> +    if (!set_nonblock)) {
> +      perror("netperf: set_nonblock");
>       exit(1);
>     }
> 
> @@ -7351,7 +7351,7 @@
>   }
> 
>   /* now that we are connected, mark the socket as non-blocking */
> -  if (fcntl(s_data, F_SETFL, O_NONBLOCK) == -1) {
> +  if (!set_nonblock(s_data)) {
>     close(s_data);
>     exit(1);
>   }
> diff -u3 -Hb -r SVN-Latest/src/nettest_sctp.c nettest_sctp.c
> --- SVN-Latest/src/nettest_sctp.c    Sun Feb 11 15:53:55 2007
> +++ nettest_sctp.c    Tue Feb 13 17:19:31 2007
> @@ -617,7 +617,7 @@
> 
>     if (non_block) {
>     /* now that we are connected, mark the socket as non-blocking */
> -    if (fcntl(send_socket, F_SETFL, O_NONBLOCK) == -1) {
> +    if (!set_nonblock(send_socket)) {
>       perror("netperf: fcntl");
>       exit(1);
>     }
> @@ -1281,7 +1281,7 @@
>   if (non_block) {
>       fprintf(where, "setting socket as nonblocking\n");
>       fflush(where);
> -      if (fcntl(s_data, F_SETFL, O_NONBLOCK) == -1) {
> +      if (!set_nonblock(s_data)) {
>     close(s_data);
>     exit(1);
>       }
> @@ -1759,7 +1759,7 @@
> 
>     if (non_block) {
>         /* now that we are connected, mark the socket as non-blocking */
> -        if (fcntl(send_socket[j], F_SETFL, O_NONBLOCK) == -1) {
> +        if (!set_nonblock(send_socket[j])) {
>           perror("netperf: fcntl");
>           exit(1);
>         }
> @@ -2429,7 +2429,7 @@
> 
>   /* now that we are connected, mark the socket as non-blocking */
>   if (non_block) {
> -      if (fcntl(s_recv, F_SETFL, O_NONBLOCK) == -1) {
> +      if (!set_nonblock(s_recv)) {
>     close(s_recv);
>     exit(1);
>       }
> @@ -2829,7 +2829,7 @@
> 
>     /* set non-blocking if needed */
>     if (non_block) {
> -    if (fcntl(send_socket, F_SETFL, O_NONBLOCK) == -1) {
> +       if (!set_nonblock(send_socket)) {
>         close(send_socket);
>         exit(1);
>     }
> @@ -3450,8 +3450,8 @@
> 
>   /* now that we are connected, mark the socket as non-blocking */
>   if (non_block) {
> -    if (fcntl(s_data, F_SETFL, O_NONBLOCK) == -1) {
> -    perror("netperf: fcntl");
> +    if (!set_nonblock(s_data)) {
> +      perror("netperf: set_nonblock");
>     exit(1);
>     }
>   }
> @@ -3888,7 +3888,7 @@
>       sctp_enable_events(send_socket[j], 0);
> 
>       if (non_block) {
> -    if (fcntl(send_socket[j], F_SETFL, O_NONBLOCK) == -1) {
> +        if (!set_nonblock(send_socket[j])) {
>       close(send_socket[j]);
>       exit(1);
>     }
> @@ -4492,8 +4492,8 @@
> 
>   /* now that we are connected, mark the socket as non-blocking */
>   if (non_block) {
> -    if (fcntl(s_rcv, F_SETFL, O_NONBLOCK) == -1) {
> -    perror("netperf: fcntl");
> +    if (!set_nonblock(s_rcv)) {
> +      perror("netperf: set_nonblock");
>     exit(1);
>     }
>   }
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> netperf-talk mailing list
> netperf-talk at netperf.org
> http://www.netperf.org/cgi-bin/mailman/listinfo/netperf-talk



More information about the netperf-talk mailing list