Changeset 7992 for trunk/src


Ignore:
Timestamp:
Feb 23, 2002, 5:39:10 PM (24 years ago)
Author:
sandervl
Message:

Don't send FD_CONNECT for sockets that are returned by accept

Location:
trunk/src/wsock32
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wsock32/asyncapi.cpp

    r7977 r7992  
    1 /* $Id: asyncapi.cpp,v 1.19 2002-02-20 15:07:13 sandervl Exp $ */
     1/* $Id: asyncapi.cpp,v 1.20 2002-02-23 16:39:09 sandervl Exp $ */
    22
    33/*
     
    531531        ret = select((int *)sockets, nr(noread), nr(nowrite), nr(noexcept), -1);
    532532        pThreadParm->fWaitSelect = FALSE;
     533
    533534        if(ret == SOCKET_ERROR) {
    534535                int selecterr = sock_errno();
     
    542543////                    state = ioctl(s, FIOBSTATUS, (char *)&tmp, sizeof(tmp));
    543544////                    dprintf(("SOCEINTR; state = %x", state));
    544                         goto asyncloopstart;    //so_cancel was called
     545                        goto asyncloopstart;    //so_cancel/closesocket was called
    545546
    546547                case SOCECONNRESET:
     
    574575                state = ioctl(s, FIOBSTATUS, (char *)&tmp, sizeof(tmp));
    575576
    576                 if(lEventsPending & FD_CONNECT) {
     577                //Don't send FD_CONNECT is socket was already connected (accept returns connected socket)
     578                if(!pThreadParm->fConnected && (lEventsPending & FD_CONNECT))
     579                {
    577580                        if(state & SS_ISCONNECTED) {
    578581                                AsyncSelectNotifyEvent(pThreadParm, FD_CONNECT, NO_ERROR);
     582                                pThreadParm->fConnected = TRUE;
    579583                        }
    580584                        else {
     
    594598                }
    595599        }
    596 
    597600        if(ready(noread))
    598601        {
    599602                state = ioctl(s, FIONREAD, (CHAR *) &bytesread, sizeof(bytesread));
     603                dprintf2(("state %x, bytesread %d", state, bytesread));
    600604                if(state == SOCKET_ERROR)
    601605                {
     
    769773        return SOCKET_ERROR;
    770774   }
     775
     776   int size, state, tmp;
     777   state = ioctl(s, FIOBSTATUS, (char *)&tmp, sizeof(tmp));
     778   dprintf(("QueueAsyncJob: state %x", state));
     779
     780   //Don't send FD_CONNECT is socket was already connected (accept returns connected socket)
     781   if(state & SS_ISCONNECTED) {
     782        pThreadParm->fConnected = TRUE;
     783   }
     784   else pThreadParm->fConnected = FALSE;
     785
    771786   if(QueueAsyncJob(WSAsyncSelectThreadProc, pThreadParm) == 0) {
    772787        delete pThreadParm->u.asyncselect.asyncSem;
  • trunk/src/wsock32/asyncthread.cpp

    r7977 r7992  
    1 /* $Id: asyncthread.cpp,v 1.14 2002-02-20 15:07:13 sandervl Exp $ */
     1/* $Id: asyncthread.cpp,v 1.15 2002-02-23 16:39:09 sandervl Exp $ */
    22
    33/*
     
    239239{
    240240 PASYNCTHREADPARM pThreadInfo;
    241  
     241
    242242   asyncThreadMutex.enter();
    243243   pThreadInfo = FindAsyncEvent(s);
    244    if(pThreadInfo) {
     244   if(pThreadInfo)
     245   {
     246        int size, state, tmp;
     247        state = ioctl(s, FIOBSTATUS, (char *)&tmp, sizeof(tmp));
     248        dprintf(("FindAndSetAsyncEvent: state %x", state));
     249
     250        //Don't send FD_CONNECT is socket was already connected (accept returns connected socket)
     251        if(state & SS_ISCONNECTED) {
     252             pThreadInfo->fConnected = TRUE;
     253        }
     254        else pThreadInfo->fConnected = FALSE;
     255
    245256        pThreadInfo->u.asyncselect.mode           = mode;
    246257        pThreadInfo->u.asyncselect.lEvents        = lEventMask;
  • trunk/src/wsock32/asyncthread.h

    r7977 r7992  
    1 /* $Id: asyncthread.h,v 1.11 2002-02-20 15:07:14 sandervl Exp $ */
     1/* $Id: asyncthread.h,v 1.12 2002-02-23 16:39:09 sandervl Exp $ */
    22
    33/*
     
    3333        BOOL            fCancelled;
    3434        BOOL            fConnected;
    35         BOOL            fWaitSelect;
     35        BOOL            fWaitSelect;       
    3636        BOOL            fRemoved;  //async select
    3737        AsyncRequestType request;
  • trunk/src/wsock32/wsock32.cpp

    r7979 r7992  
    1 /* $Id: wsock32.cpp,v 1.48 2002-02-20 16:08:03 sandervl Exp $ */
     1/* $Id: wsock32.cpp,v 1.49 2002-02-23 16:39:10 sandervl Exp $ */
    22
    33/*
     
    6565#include "dbglocal.h"
    6666
    67 //kso: dirty fix to make this compile! not permanent!
    68 BOOL WINAPI QueryPerformanceCounter(LARGE_INTEGER *p);
    69 #define LowPart u.LowPart
    70 
     67//
     68#define DUMP_PACKETS
    7169
    7270ODINDEBUGCHANNEL(WSOCK32-WSOCK32)
    73 
    7471
    7572/*****************************************************************************
     
    209206            strcpy(msg, "WSAHOST_NOT_FOUND");
    210207            break;
     208        case WSAENOPROTOOPT:
     209            strcpy(msg, "WSAENOPROTOOPT");
     210            break;
     211        case WSAEHOSTUNREACH:
     212            strcpy(msg, "WSAEHOSTUNREACH");
     213            break;
    211214        default:
    212215            strcpy(msg, "unknown");
     
    326329        return SOCKET_ERROR;
    327330   }
     331   dprintf(("connect to %s", inet_ntoa(((sockaddr_in*)name)->sin_addr)));
     332
    328333   ret = connect(s, (sockaddr *)name, namelen);
    329334   // map BSD error codes
     
    550555        //with the same parameters for the new socket (see docs)
    551556        if(QueryAsyncEvent(s, &mode, &notifyHandle, &notifyData, &lEvent) == TRUE) {
     557                dprintf(("Setting async select for socket %x, mode %d, %x %x %x", ret, mode, notifyHandle, notifyData, lEvent));
    552558                if(WSAAsyncSelectWorker(ret, mode, notifyHandle, notifyData, lEvent) == SOCKET_ERROR) {
    553559                        ret = SOCKET_ERROR;
     
    584590        return SOCKET_ERROR;
    585591   }
     592   dprintf(("bind to %s", inet_ntoa(((sockaddr_in*)addr)->sin_addr)));
    586593   ret = bind(s, (struct sockaddr *)addr, namelen);
    587594
     
    682689        }
    683690   }
    684    else WSASetLastError(NO_ERROR);
     691   else {
     692#ifdef DUMP_PACKETS
     693       dprintf(("Packet length %d", ret));
     694       for(int i=0;i<(ret+7)/8;i++) {
     695           dprintf(("%02x %02x %02x %02x %02x %02x %02x %02x %c %c %c %c %c %c %c %c", buf[i*8], buf[i*8+1], buf[i*8+2], buf[i*8+3], buf[i*8+4], buf[i*8+5], buf[i*8+6], buf[i*8+7], buf[i*8], buf[i*8+1], buf[i*8+2], buf[i*8+3], buf[i*8+4], buf[i*8+5], buf[i*8+6], buf[i*8+7]));
     696       }
     697#endif
     698       WSASetLastError(NO_ERROR);
     699   }
    685700
    686701   //Reset FD_READ event flagfor  WSAAsyncSelect thread if one was created for this socket
     
    714729        return SOCKET_ERROR;
    715730   }
     731   dprintf(("recvfrom to %s", inet_ntoa(((sockaddr_in*)from)->sin_addr)));
     732
    716733   ret = recvfrom(s, buf, len, flags, from, fromlen);
    717734
     
    719736        WSASetLastError(wsaErrno());
    720737   }
    721    else WSASetLastError(NO_ERROR);
     738   else {
     739#ifdef DUMP_PACKETS
     740       dprintf(("Packet length %d", ret));
     741       for(int i=0;i<(ret+7)/8;i++) {
     742           dprintf(("%02x %02x %02x %02x %02x %02x %02x %02x %c %c %c %c %c %c %c %c", buf[i*8], buf[i*8+1], buf[i*8+2], buf[i*8+3], buf[i*8+4], buf[i*8+5], buf[i*8+6], buf[i*8+7], buf[i*8], buf[i*8+1], buf[i*8+2], buf[i*8+3], buf[i*8+4], buf[i*8+5], buf[i*8+6], buf[i*8+7]));
     743       }
     744#endif
     745       WSASetLastError(NO_ERROR);
     746   }
    722747
    723748   //Reset FD_READ event flagfor  WSAAsyncSelect thread if one was created for this socket
     
    734759{
    735760   int ret;
     761   int optlen;
     762   int option;
    736763
    737764   if(!fWSAInitialized) {
     
    744771        return SOCKET_ERROR;
    745772   }
     773   // check if the socket is a raw socket and has the IP_HDRINCL switch
     774   // if this is the case, we overwrite the IP header length field with
     775   // the actual length because some apps tend to put garbage in there
     776   // and rely on Windows to correct this
     777   optlen = sizeof(option);
     778   option = 0;
     779   ret = getsockopt(s, IPPROTO_IP, IP_HDRINCL_OS2, (char *)&option, &optlen);
     780   if(ret == 0 && option != FALSE) {
     781       *(u_short *)&buf[2] = len;
     782   }
     783
     784#ifdef DUMP_PACKETS
     785   dprintf(("Packet length %d", len));
     786   for(int i=0;i<(len+7)/8;i++) {
     787           dprintf(("%02x %02x %02x %02x %02x %02x %02x %02x %c %c %c %c %c %c %c %c", buf[i*8], buf[i*8+1], buf[i*8+2], buf[i*8+3], buf[i*8+4], buf[i*8+5], buf[i*8+6], buf[i*8+7], buf[i*8], buf[i*8+1], buf[i*8+2], buf[i*8+3], buf[i*8+4], buf[i*8+5], buf[i*8+6], buf[i*8+7]));
     788   }
     789#endif
    746790   ret = send(s, (char *)buf, len, flags);
    747791
     
    785829   // check if the socket is a raw socket and has the IP_HDRINCL switch
    786830   // if this is the case, we overwrite the IP header length field with
    787    // the actual length because some apps tend to put in garbage in there
    788    // and rely on Windows correcting this
     831   // the actual length because some apps tend to put garbage in there
     832   // and rely on Windows to correct this
    789833   optlen = sizeof(option);
    790834   option = 0;
     
    794838   }
    795839   dprintf(("sending to %s", inet_ntoa(((sockaddr_in*)to)->sin_addr)));
     840#ifdef DUMP_PACKETS
     841   dprintf(("Packet length %d", len));
     842   for(int i=0;i<(len+7)/8;i++) {
     843           dprintf(("%02x %02x %02x %02x %02x %02x %02x %02x %c %c %c %c %c %c %c %c", buf[i*8], buf[i*8+1], buf[i*8+2], buf[i*8+3], buf[i*8+4], buf[i*8+5], buf[i*8+6], buf[i*8+7], buf[i*8], buf[i*8+1], buf[i*8+2], buf[i*8+3], buf[i*8+4], buf[i*8+5], buf[i*8+6], buf[i*8+7]));
     844   }
     845#endif
    796846   ret = sendto(s, (char *)buf, len, flags, (struct sockaddr *)to, tolen);
    797847
     
    10521102                        return SOCKET_ERROR;
    10531103                }
     1104                dprintf(("IPPROTO_TCP, TCP_NODELAY 0x%x", *optval));
    10541105                ret = setsockopt(s, level, optname, (char *)optval, optlen);
    10551106        }
Note: See TracChangeset for help on using the changeset viewer.