All pastes #2068552 Raw Edit

Anonymous

public text v1 · immutable
#2068552 ·published 2011-05-24 16:34 UTC
rendered paste body
Client( const std::string& host, const std::string& port )
      {
        struct addrinfo hint;
        struct addrinfo* serv;
        int sockfd;

        memset( &hint, 0, sizeof( hint ) );
        hint.ai_family = AF_UNSPEC;
        hint.ai_socktype = SOCK_STREAM;

        getaddrinfo( host.c_str(), port.c_str(), &hint, &serv );

        sd = socket( serv->ai_family, serv->ai_socktype, serv->ai_protocol );

        connect( sd, serv->ai_addr, serv->ai_addrlen );

        freeaddrinfo( serv );
      }

      unsigned int send( const unsigned long long i, const char q )
      {
        const char* str( "some user query" );
        char buf[ 512 ];

        snprintf( buf, 512, "%s %llu %c", str, i, q );

        timeval s;
        gettimeofday( &s, 0 );

        write( sd, buf, strlen( buf ) );
        read( sd, buf, 512 );

        timeval e;
        gettimeofday( &e, 0 );

        return( (e.tv_sec - s.tv_sec ) * 1000000 + e.tv_usec - s.tv_usec );
      }