It is currently Fri, 17 Aug 2018 23:43:56 GMT



 
Author Message
 Sockets problem
Hi all,

I'm getting this error while trying to connect to a socket on a seperate
machine.
EALREADY - Operation now in progress
I'm running on a Solaris 2.6 OS, C code.

I'm asking for help on explaining to me what this error really means.
And if I'm missing something in my code.

I can connect fine to a listener on the same machine no problem.

Thanks
Rob
Toronto, Canada
rtol...@interlog.com

This is my Connection function:
============================================
int start_tcp()
{
 struct  sockaddr_in server;
 int  sd;
 struct  hostent *host;
 time_t  srvrtime;
 char data[LARGE_STRING];

 if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
  perror("socket error");
  exit(1);
 }

 set_fl(sd ,O_NONBLOCK);  /*  set nonblocking flag */

 memset((char*) &server, '\0',sizeof(server));
 server.sin_family = AF_INET;
 server.sin_port = PORTNUM;

 if ((host = gethostbyname(CARDTEL_NAME)) == NULL){
  perror("gethostbyname error");
  exit(1);
 }

 memcpy ((char*)&server.sin_addr, host->h_addr, host->h_length);

 if( connect(sd, (struct sockaddr*)&server, sizeof(server))){
  perror("connect error");  /* this is where the error occurs */
  fprintf(bugfd,"errno:%d\n",errno);
  exit(1);
 }

 return sd;
============================================



 Sun, 11 Nov 2001 03:00:00 GMT   
 Sockets problem

 Rob> Hi all,

 Rob> I'm getting this error while trying to connect to a socket on a
 Rob> seperate machine.
 Rob> EALREADY - Operation now in progress

I'd expect "EINPROGRESS" given your source code.

When you call connect() on a socket in non-blocking mode, one of three
things can happen:

  - an immediate error occurs, in which case the call returns -1 and
    the appropriate errno

  - the connect completes without sleeping, which generally can only
    happen if connecting to the same machine, in which case the call
    returns 0 and the socket is now connected

  - the connect begins but can't complete without sleeping, in which
    case the call returns -1 and EINPROGRESS. The system is still trying
    to complete the connection in this case. The socket will not select
    as writable until either the connection completes or it fails.

--
Andrew.

comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
                           or <URL: http://www.whitefang.com/unix/>



 Sun, 11 Nov 2001 03:00:00 GMT   
 Sockets problem
You get this error (which is not an error) because you
set your socket as O_NONBLOCK. Thus the connect() call
is non blocking. Either you stay that way and use select()
to know when the connect() completes or you set
the socket as non blocking after the call to connect().

gg



 Mon, 12 Nov 2001 03:00:00 GMT   
 Sockets problem
Thanks for the info,

OK so if I don't go into nonblocking mode, (I don't really need to) I only
did it so I didn't timeout at recv(). I can get around this with other
timeout methods such as select().

I tried this I do connect now, but I don't appear to hold the connection to
the socket.
What do you suggest?
I am new at this and I'm reading and learning as I go, I need a little push
to get over this hump.

I have UNP volume 1 and Advanced Programming in Unix books both by Stevens
in front of me.

Rob

news:87k8tvcyya.fsf@erlenstar.demon.co.uk...
http://www.erlenstar.demon.co.uk/unix/>

- Show quoted text -



 Mon, 12 Nov 2001 03:00:00 GMT   
 
   [ 4 post ] 

Similar Threads

1. socket help and other sockets problems !?!?

2. ISDN Router problem/socket problem

3. PROBLEM: Interface address change netlink socket problem.(Patch attached)

4. socket problem and mysql (part 2)

5. Socket problem with PCMCIA package

6. ?: help with unix-type socket problem in rh5.2/kern 2.2.1

7. wu.ftpd socket problem

8. Socket problems w/ new kernel

9. Wierd TCP socket problem

10. Linux Socket Problem?


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software