delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin-developers/2002/07/05/03:58:21

Mailing-List: contact cygwin-developers-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-developers-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin-developers/>
List-Post: <mailto:cygwin-developers AT cygwin DOT com>
List-Help: <mailto:cygwin-developers-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-developers-owner AT cygwin DOT com
Delivered-To: mailing list cygwin-developers AT cygwin DOT com
X-Authentication-Warning: atacama.four-d.de: mail set sender to <tpfaff AT gmx DOT net> using -f
Date: Fri, 5 Jul 2002 09:58:05 +0200 (=?ISO-8859-1?Q?Westeurop=E4ische_Sommerzeit?=)
From: Thomas Pfaff <tpfaff AT gmx DOT net>
To: cygwin-developers AT cygwin DOT com
Subject: Re: Interruptable connect
In-Reply-To: <Pine.WNT.4.44.0207041622360.264-100000@algeria.intern.net>
Message-ID: <Pine.WNT.4.44.0207050945190.294-100000@algeria.intern.net>
X-X-Sender: pfaff AT antarctica DOT intern DOT net
MIME-Version: 1.0


On Thu, 4 Jul 2002, Thomas Pfaff wrote:

>
>
> On Thu, 4 Jul 2002, Corinna Vinschen wrote:
>
> > On Thu, Jul 04, 2002 at 02:54:44PM +0200, Thomas Pfaff wrote:
> > > > Sure, but how will this help ? You can not look ahead if the connect will
> > > > be reentered or not. If the program is well written it will or close the
> > > > socket afterwards, but should i rely on this ?
> > > >
> > >
> > > To be more precise:
> > > I have no problems with unclosed sockets but with a connected socket
> > > that shouldn't be connected.
> >
> > I see.  The question is if we're able to get around that Winsock'ism.
> >
> > Perhaps Winsock2 helps a bit.
> >
> > This is just brainstorming, I have no idea if that works:
> >
> > When connect is called, create a duplicate of the socket first,
> > before actually connecting, using the WSADuplicateSocket call.
> > This should give you a structure describing the socket in exactly
> > the state before the ::connect call.  Now for the cases:
> >
> > - Normal connect, success, erase the duplicate.
> > - Normal connect, failure, ditto.
> > - Interrupt, close original socket and recreate it from the duplicate
> >   using WSASocket.
> >
> > Would that work???
> >
>
> Sounds good, but i am not 100 % sure if the duplicated socket is created
> in exactly the same state than the original one before WSAEventSelect.
> The remarks in WSADuplicateSocket are not clear, especially whether it is
> possible to close the original socket first and then create the duplicate.
> I will make some tests.
>

Unfortunately this does't help here. If i call WSADuplicateSocket the
socket is really a duplicate, it is not closed until i create a new socket
with WSASocket. I have attached my test prog.
The connection is not closed by closesocket after the first connect and
the second connect will fail with WSAISCONN.

Thomas

#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>

int main(void)
{

   WSADATA wsaData;
   SOCKET sock;

   WSAPROTOCOL_INFO proto_info;

   struct sockaddr_in s_server;

   struct sockaddr_in sin;
   struct sockaddr_in s_test;
   int namelen = sizeof(s_test);

   WSAStartup( 0x202, &wsaData );

   sock = socket(AF_INET,SOCK_STREAM,0);

   sin.sin_family = AF_INET;
   sin.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
   sin.sin_port = htons( 5679 );

   bind( sock, (struct sockaddr*) &sin, sizeof( sin ) );

   if (WSADuplicateSocket(sock, GetCurrentProcessId(), &proto_info))
   {
      int err = WSAGetLastError();

      return 3;
   }

   s_server.sin_family = AF_INET;;
   s_server.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
   s_server.sin_port = htons( 5678 );
   if( connect( sock, (struct sockaddr*) &s_server, sizeof( s_server ) ) <
0 )
   {
      printf( "%d\n", WSAGetLastError());
      return 0;
   }
   closesocket(sock);
   sock = WSASocket( FROM_PROTOCOL_INFO,
                     FROM_PROTOCOL_INFO,
                     FROM_PROTOCOL_INFO,
                     &proto_info, 0, 0);
   if( connect( sock, (struct sockaddr*) &s_server, sizeof( s_server ) ) <
0 )
   {
      printf( "%d\n", WSAGetLastError());
      return 0;
   }

   closesocket(sock);

   return 0;
}


- Raw text -


  webmaster     delorie software   privacy  
  Copyright 2019   by DJ Delorie     Updated Jul 2019