sa.inet.port = PORT_BASE + *id;
sa.inet.port = PR_htons(PORT_BASE + *id);
_server_thread(void *arg_id){	void _client_thread(void *);	PRThread *thread;	int *id =  (int *)arg_id;	PRFileDesc *sock;	PRNetAddr sa;	PRFileDesc * newsock;	char *data_buffer = NULL;	int data_buffer_size;	int index;	PRIntervalTime start,	      connect_done,	      read_done,	      write_done,	      close_done;	#ifdef DEBUG	fprintf(stdout, "server thread %d alive\n", *id);#endif	data_buffer_size = (_client_data>_server_data?_client_data:_server_data);	if ( (data_buffer = (char *)PR_Malloc(data_buffer_size * sizeof(char))) == NULL ) {		fprintf(stderr, "Error creating buffer in server thread %d\n", *id);		goto done;	}	if ( (sock = PR_NewTCPSocket()) == NULL) {		fprintf(stderr, "Error creating socket in server thread %d\n", *id);		goto done;	}	memset(&sa, 0 , sizeof(sa));	sa.inet.family = PR_AF_INET;	sa.inet.port = PORT_BASE + *id;	sa.inet.ip = PR_htonl(PR_INADDR_ANY);	if ( PR_Bind(sock, &sa) < 0) {		fprintf(stderr, "Error binding socket in server thread %d errno = %d\n", *id, errno);		goto done;	}#if 0	{		int one = 1;		setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (const char *)&one, sizeof(one));	}#endif	if ( PR_Listen(sock, 32) < 0 ) {		fprintf(stderr, "Error listening to socket in server thread %d\n", *id);		goto done;	}	/* Tell the client to start */	if ( (thread = PR_CreateThread(PR_USER_THREAD,                                       _client_thread,                                       id,                                       PR_PRIORITY_NORMAL,                                       scope2,                                       PR_UNJOINABLE_THREAD,                                       0)) == NULL)		fprintf(stderr, "Error creating client thread %d\n", *id);	for (index = 0; index< _iterations; index++) {#ifdef DEBUG	fprintf(stdout, "server thread %d loop %d\n", *id, index);#endif		start = PR_IntervalNow();		if ( (newsock = PR_Accept(sock, &sa,					PR_INTERVAL_NO_TIMEOUT)) == NULL) {			fprintf(stderr, "Error accepting connection %d in server thread %d\n",				index, *id);			goto done;		}#ifdef DEBUG	fprintf(stdout, "server thread %d got connection %d\n", *id, newsock);#endif		connect_done = PR_IntervalNow();				if ( _readn(newsock, data_buffer, _client_data) < _client_data) {			fprintf(stderr, "Error reading client data for iteration %d in server thread %d\n", index, *id );			goto done;		}#ifdef DEBUG	fprintf(stdout, "server thread %d read %d bytes\n", *id, _client_data);#endif		read_done = PR_IntervalNow();		if ( PR_Send(newsock, data_buffer, _server_data, 0,				PR_INTERVAL_NO_TIMEOUT) < _server_data) {			fprintf(stderr, "Error sending client data for iteration %d in server thread %d\n", index, *id );			goto done;		}#ifdef DEBUG	fprintf(stdout, "server thread %d write %d bytes\n", *id, _server_data);#endif		write_done = PR_IntervalNow();		PR_Close(newsock);		close_done = PR_IntervalNow();		timer_data[2*(*id)].d_connect += _delta(&start, &connect_done);		timer_data[2*(*id)].d_cl_data += _delta(&connect_done, &read_done);		timer_data[2*(*id)].d_sv_data += _delta(&read_done, &write_done);		timer_data[2*(*id)].d_close += _delta(&write_done, &close_done);		timer_data[2*(*id)].d_total += _delta(&start, &close_done);		timer_data[2*(*id)].requests++;#ifdef DEBUG		fprintf(stdout, "server: %d %d %d %d %d\n",			 _delta(&start, &connect_done), _delta(&connect_done, &read_done),			 _delta(&read_done, &write_done), _delta(&write_done, &close_done),			_delta(&start, &close_done));#endif	}done:	if (data_buffer != NULL) PR_Free (data_buffer);	if (sock) PR_Close(sock);	_thread_exit(*id);	return;}