[comp.unix.questions] Socket question

mtsu@blake.acs.washington.edu (Montana State) (03/01/89)

Hokay, I hope this is a really stupid question...  E-mail responses if this
is too basic...

I have this program I'm writing which is running as a server on our network.

Everything works fine, except when I'm all done, or I get an error
condition, I just want to blow the whole thing away and restart.  What I have
so far is:

  All the socket set up stuff
  execute garbage, return answer
  If error then
    shutdown(socket,(int)2);
    close(socket)

    execve(argv[0],argv,envp);

The execve executes, but the program bombs on the bind() call with
an "address already in use" message.  How do I get this "address"
released so I can restart it.  Or is execve the wrong call??

Jaye Mathisen
icsu6000@caesar.cs.montana.edu

ugoday@sunybcs.uucp (Abdi Oday) (03/04/89)

In article <1006@blake.acs.washington.edu> icsu6000@caesar.cs.montana.edu (Jaye Mathisen) writes:
>
>
>Everything works fine, except when I'm all done, or I get an error
>condition, I just want to blow the whole thing away and restart.  What I have
>so far is:
>
>  All the socket set up stuff
>  execute garbage, return answer
>  If error then
>    shutdown(socket,(int)2);
>    close(socket)
>
>    execve(argv[0],argv,envp);
>
>The execve executes, but the program bombs on the bind() call with
>an "address already in use" message.  How do I get this "address"
>released so I can restart it.  Or is execve the wrong call??
>
>Jaye Mathisen
>icsu6000@caesar.cs.montana.edu


 I think what you want to do is queue thinks up on your socket.  In other 
 words, on the "listen" call, you tell it how many calls to queue up.

 example:

	     listen(socket, 10)

 will queue up 10 requests.  Otherwise after you close connection, it takes a
 while (sometimes 2 minutes ... I don't understand why) for a bind to work.


 Hope that helps

 -Abdi


Abdi Oday                       Phone:     (716) 636-3004
University at Buffalo           BITNET:    ugoday@sunybcs.BITNET
				Internet:  ugoday@cs.Buffalo.EDU
UUCP: ...!{ames,boulder,decvax,rutgers}!sunybcs!ugoday

andrew@alice.UUCP (Andrew Hume) (03/05/89)

i understand the problem to be that if you tear down a socket that you
got as a result of listening to an address that you 'bind'ed to
and then attempt to bind again, you get an address in use error.

this is annoyingly correct behaviour. some standard says the address
is taken for up to 4 minutes. i have a similar problem and i adopt
the sendmail approach (it has to be good for something, right?)
and set some socket option to reuse the address and then just rebind
over the top.

rayan@cs.toronto.edu (Rayan Zachariassen) (10/27/89)

Speaking of sockets, why doesn't SIGIO seem to work on a bound and listened-to
but not accepted file descriptor?  Assume the FASYNC flag is set and the
notified-pid is correct.  Did I do something else wrong?  Would SIGPOLL work
in that situation if the networking was streams-based instead of 4.3 code ?
Yes, select would work, but I'd like an async (non-polled) notification that
someone is trying to talk to me.

ecsv24@castle.ed.ac.uk (J Bradfield) (10/28/89)

I have a problem understanding the behaviour of sockets, though the
answer may involve the stdio library instead.
On Suns or Pyramids, consider the following sequence of events:
Server Process                   Client Process
listen's on a TCP port            
accept's                         connect's to server
fdopen's socket & setbuf's to    fdopen's socket
 unbuffered
receives data (fscanf etc) and   sends data (fprintf etc) and rewind's
 rewind's                         
sends data                       receives data
                                 getc's on the socket stream
                                 process receives signal and signal
                                  handler exits.
putc's one character on socket stream
 returns without error
putc's one character again
 returns error indication



Why does the server process get an error on the second putc, not the first?