if (bytesWritten != _server_data)
if (bytesWritten != _server_data) {
WorkerThreadFunc(void *_listenSock){    PRFileDesc *listenSock = (PRFileDesc *)_listenSock;    PRInt32 bytesRead;    PRInt32 bytesWritten;    char *dataBuf;    char *sendBuf;    if (debug_mode) DPRINTF("\tServer buffer is %d bytes; %d data, %d netaddrs\n",            _client_data+(2*sizeof(PRNetAddr))+32, _client_data, (2*sizeof(PRNetAddr))+32);    dataBuf = (char *)PR_MALLOC(_client_data + 2*sizeof(PRNetAddr) + 32);    if (!dataBuf)        if (debug_mode) printf("\tServer could not malloc space!?\n");    sendBuf = (char *)PR_MALLOC(_server_data *sizeof(char));    if (!sendBuf)        if (debug_mode) printf("\tServer could not malloc space!?\n");    if (debug_mode) DPRINTF("\tServer worker thread running\n");    while(1) {        PRInt32 bytesToRead = _client_data;        PRInt32 bytesToWrite = _server_data;        PRFileDesc *newSock;        PRNetAddr *rAddr;        PRInt32 loops = 0;        loops++;        if (debug_mode) DPRINTF("\tServer thread going into accept\n");        bytesRead = PR_AcceptRead(listenSock,                                   &newSock,                                  &rAddr,                                  dataBuf,                                  bytesToRead,                                  PR_INTERVAL_NO_TIMEOUT);        if (bytesRead < 0) {            if (debug_mode) printf("\tServer error in accept (%d)\n", bytesRead);            continue;        }        if (debug_mode) DPRINTF("\tServer accepted connection (%d bytes)\n", bytesRead);                PR_AtomicIncrement(&workerThreadsBusy);        if (workerThreadsBusy == workerThreads) {            PR_Lock(workerThreadsLock);            if (workerThreadsBusy == workerThreads) {                PRThread *WorkerThread;                WorkerThread = PR_CreateThread(                                  PR_SYSTEM_THREAD,                                  WorkerThreadFunc,                                  listenSock,                                  PR_PRIORITY_NORMAL,                                  ServerScope,                                  PR_UNJOINABLE_THREAD,                                  THREAD_STACKSIZE);                if (!WorkerThread)                    if (debug_mode) printf("Error creating client thread %d\n", workerThreads);                else {                    PR_AtomicIncrement(&workerThreads);                    if (debug_mode) DPRINTF("\tServer creates worker (%d)\n", workerThreads);                }            }            PR_Unlock(workerThreadsLock);        }         bytesToRead -= bytesRead;        while (bytesToRead) {            bytesRead = PR_Recv(newSock,                                 dataBuf,                                 bytesToRead,                                 0,                                 PR_INTERVAL_NO_TIMEOUT);            if (bytesRead < 0) {                if (debug_mode) printf("\tServer error receiving data (%d)\n", bytesRead);                continue;            }            if (debug_mode) DPRINTF("\tServer received %d bytes\n", bytesRead);        }        bytesWritten = PR_Send(newSock,                               sendBuf,                                bytesToWrite,                                0,                                PR_INTERVAL_NO_TIMEOUT);        if (bytesWritten != _server_data)            if (debug_mode) printf("\tError sending data to client (%d, %d)\n",                 bytesWritten, PR_GetOSError());        else            if (debug_mode) DPRINTF("\tServer sent %d bytes\n", bytesWritten);        PR_Close(newSock);        PR_AtomicDecrement(&workerThreadsBusy);    }}