PR_ProcessExit(1); } sock_opt.option = PR_SockOpt_Reuseaddr; sock_opt.value.reuse_addr = PR_TRUE; rv = PR_SetSocketOption(listen_sock, &sock_opt); if (PR_FAILURE == rv) { PL_FPrintError(err_out, "PR_SetSocketOption (server) failed");
static void AcceptingThread(void *arg){    PRStatus rv;    PRInt32 bytes;    PRSize buf_size = BUF_SIZE;    PRUint8 buf[BUF_SIZE + (20 * sizeof(PRNetAddr))];    PRNetAddr *accept_addr, *listen_addr = (PRNetAddr*)arg;    PRFileDesc *accept_sock, *listen_sock = PR_NewTCPSocket();    if (NULL == listen_sock)    {        PL_FPrintError(err_out, "PR_NewTCPSocket (server) failed");        PR_ProcessExit(1);            }    rv = PR_Bind(listen_sock, listen_addr);    if (PR_FAILURE == rv)    {        PL_FPrintError(err_out, "PR_Bind (server) failed");        PR_ProcessExit(1);            }    rv = PR_Listen(listen_sock, 10);    if (PR_FAILURE == rv)    {        PL_FPrintError(err_out, "PR_Listen (server) failed");        PR_ProcessExit(1);            }    bytes = PR_AcceptRead(        listen_sock, &accept_sock, &accept_addr, buf, buf_size, accept_timeout);    if (-1 == bytes) PL_FPrintError(err_out, "PR_AcceptRead (server) failed");    else    {        PrintAddress(accept_addr);        PR_fprintf(            std_out, "(Server) read [0x%p..0x%p) %s\n",            buf, &buf[BUF_SIZE], buf);        bytes = PR_Write(accept_sock, buf, bytes);        rv = PR_Shutdown(accept_sock, PR_SHUTDOWN_BOTH);        if (PR_FAILURE == rv)            PL_FPrintError(err_out, "PR_Shutdown (server) failed");    }    if (-1 != bytes)    {        rv = PR_Close(accept_sock);        if (PR_FAILURE == rv)            PL_FPrintError(err_out, "PR_Close (server) failed");    }    rv = PR_Close(listen_sock);    if (PR_FAILURE == rv)        PL_FPrintError(err_out, "PR_Close (server) failed");}  /* AcceptingThread */