Re: Problems listening at ports

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



try using the SO_LINGER option with the setsockopt
think this should solve ur problem 

-SIGTERM
amit
----- Original Message ----- 
From: "Lukas Ruf" <ruf@rawip.org>
To: "Kernel Newbies" <kernelnewbies@nl.linux.org>
Sent: Friday, May 09, 2003 3:05 PM
Subject: Problems listening at ports


> Dear all,
> 
> when making use of the following code fragment, I cannot start the
> program immediately again after it finished. 
> 
> /* BEGIN Fragment */
> /* I removed all the error checking to shorten the code */
> 
>   getaddrinfo(host, service, &hints, &res);
>   listenfd = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
>   setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
>   bind(listenfd, res->ai_addr, res->ai_addrlen);
>   listen(listenfd, LISTENQ);
>   fd = accept(listenfd, sa, &salen);
>   close(fd);
>   close(listenfd);
> 
> /* END Fragment */
> 
> When I compile this code fragment, it starts perfectly and awaits a
> connection.  If I restart the program immediately afterwards from
> within a loop in a shell script, listen() fails.  If I wait for a
> second (sleep 1) before restarting the program, everything works fine
> again.
> 
> Does anybody know what I made wrong?
> 
> Thanks for any enlightenment!
> 
> wbr,
> Lukas
> -- 
> Lukas Ruf           | Wanna know anything about raw |
> <http://www.lpr.ch> | IP?  <http://www.rawip.org>   |
> --
> Kernelnewbies: Help each other learn about the Linux kernel.
> Archive:       http://mail.nl.linux.org/kernelnewbies/
> FAQ:           http://kernelnewbies.org/faq/
> 

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux