PR_ASSERT(me->io_pending == PR_FALSE);
_PR_MD_FAST_ACCEPT_READ(PRFileDesc *sd, PRInt32 *newSock, PRNetAddr **raddr,                    void *buf, PRInt32 amount, PRIntervalTime timeout,                    PRBool fast, _PR_AcceptTimeoutCallback callback,                    void *callbackArg){    PRInt32 sock = sd->secret->md.osfd;    PRThread *me = _PR_MD_CURRENT_THREAD();    int bytes;    PRNetAddr *Laddr;    PRUint32 llen, rlen, err;    int rv;    PRBool isConnected;    PRBool madeCallback = PR_FALSE;    if (!_nt_use_async) {        PRFileDesc *nd;        bytes = _PR_EmulateAcceptRead(sd, &nd, raddr, buf, amount, timeout);        if (bytes != -1) {            /*             * This part is the same as SocketClose(nd), except             * that we don't close the osfd.             */            PR_ASSERT(nd->secret->state == _PR_FILEDESC_OPEN);            *newSock = nd->secret->md.osfd;            PR_FreeFileDesc(nd);        }        return bytes;    }    if (me->io_suspended) {        PR_SetError(PR_INVALID_STATE_ERROR, 0);        return -1;    }    if (!sd->secret->md.io_model_committed) {        rv = _md_Associate((HANDLE)sock);        PR_ASSERT(0 != rv);        sd->secret->md.io_model_committed = PR_TRUE;    }    *newSock = _md_get_recycled_socket();    if (*newSock == INVALID_SOCKET)        return -1;    memset(&(me->md.overlapped.overlapped), 0, sizeof(OVERLAPPED));	if (_native_threads_only)		me->md.overlapped.overlapped.hEvent = me->md.thr_event;    _PR_THREAD_LOCK(me);	if (_PR_PENDING_INTERRUPT(me)) {		me->flags &= ~_PR_INTERRUPT;		PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);    	_PR_THREAD_UNLOCK(me);		return -1;	}    me->io_pending = PR_TRUE;    me->state = _PR_IO_WAIT;    _PR_THREAD_UNLOCK(me);    me->io_fd = sock;    rv = AcceptEx((SOCKET)sock,                  *newSock,                  buf,                  amount,                  INET_ADDR_PADDED,                  INET_ADDR_PADDED,                  &bytes,                  &(me->md.overlapped.overlapped));    if ( (rv == 0) && ((err = GetLastError()) != ERROR_IO_PENDING)) {		_PR_THREAD_LOCK(me);		me->io_pending = PR_FALSE;		me->state = _PR_RUNNING;		if (_PR_PENDING_INTERRUPT(me)) {			me->flags &= ~_PR_INTERRUPT;			PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);			_PR_THREAD_UNLOCK(me);			return -1;		}		_PR_THREAD_UNLOCK(me);		_PR_MD_MAP_ACCEPTEX_ERROR(err);        return -1;    }    if (_native_threads_only && rv) {        _native_thread_io_nowait(me, rv, bytes);    } else if (_NT_IO_WAIT(me, timeout) == PR_FAILURE) {        PR_ASSERT(0);        return -1;    }retry:    if (me->io_suspended) {        PRInt32 err;        INT seconds;        INT bytes = sizeof(seconds);        PR_ASSERT(timeout != PR_INTERVAL_NO_TIMEOUT);        err = getsockopt(*newSock,                          SOL_SOCKET,                         SO_CONNECT_TIME,                         (char *)&seconds,                         (PINT)&bytes);        if ( err == NO_ERROR ) {            PRIntervalTime elapsed = PR_SecondsToInterval(seconds);            if (seconds == 0xffffffff)                 isConnected = PR_FALSE;            else                 isConnected = PR_TRUE;            if (!isConnected) {                if (madeCallback == PR_FALSE && callback)                    callback(callbackArg);                madeCallback = PR_TRUE;                me->state = _PR_IO_WAIT;                if (_NT_ResumeIO(me, timeout) == PR_FAILURE)                    return -1;                goto retry;            }            if (elapsed < timeout) {                /* Socket is not connected but time not elapsed, RESUME IO */                timeout -= elapsed;                me->state = _PR_IO_WAIT;                if (_NT_ResumeIO(me, timeout) == PR_FAILURE)                    return -1;                goto retry;            }        } else {            /*  What to do here? Assume socket not open?*/            PR_ASSERT(0);            isConnected = PR_FALSE;        }        rv = _NT_IO_ABORT(*newSock);        PR_ASSERT(me->io_suspended ==  PR_FALSE);        PR_ASSERT(me->io_pending ==  PR_FALSE);        /* If the IO is still suspended, it means we didn't get any          * completion from NT_IO_WAIT.  This is not disasterous, I hope,         * but it may mean we still have an IO outstanding...  Try to          * recover by just allowing ourselves to continue.         */        me->io_suspended = PR_FALSE;        if (_PR_PENDING_INTERRUPT(me)) {            me->flags &= ~_PR_INTERRUPT;            PR_SetError(PR_PENDING_INTERRUPT_ERROR, 0);        } else {            PR_SetError(PR_IO_TIMEOUT_ERROR, 0);        }        me->state = _PR_RUNNING;        return -1;    }    PR_ASSERT(me->io_pending == PR_FALSE || me->io_suspended == PR_TRUE);    if (me->md.blocked_io_status == 0) {		_PR_MD_MAP_ACCEPTEX_ERROR(me->md.blocked_io_error);        closesocket(*newSock);        return -1;    }    if (!fast)         _PR_MD_UPDATE_ACCEPT_CONTEXT((SOCKET)*newSock, (SOCKET)sock);    /* IO is done */    GetAcceptExSockaddrs(            buf,            amount,            INET_ADDR_PADDED,            INET_ADDR_PADDED,            (LPSOCKADDR *)&(Laddr),            &llen,            (LPSOCKADDR *)(raddr),            (unsigned int *)&rlen);    PR_ASSERT(me->io_pending == PR_FALSE);    return me->md.blocked_io_bytes;}