- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to reject a socket connection?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-22-2004 03:26 AM
тАО07-22-2004 03:26 AM
How to reject a socket connection?
Basically, I 'select' on my socket descriptor (sd), and take in any connections on my server. After accepting 8 connections, I would'nt want to accept any more connections. So, I would 'accept' that 9th connection and immediately 'close' the returned fd. But, this does'nt seem to work always, because my subsequent call to 'select' on the 'sd', succeeds thinking that there is some connection to accept, which is not the case. I hope 'connect' does not automatically retry, if it receives a failure immediately after an accept. Is it possible that accept does'nt clean up the socket properly and is there someway we could manually force it?
The behaviour is not consistently observed -- it happens only in 1 out of 4 attempts.
I am using HPUX11.11. I tried, in vain, searching for patches on the similar lines. If anybody is aware of patch or an alternate solution for this, please share the same.
Thanks,
Suresh R
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-22-2004 06:15 AM
тАО07-22-2004 06:15 AM
Re: How to reject a socket connection?
shutdown(sd,how) where,
If how is SHUT_RD, further
receptions will be disallowed.
set how=1 or how=SHUT_RD
It will stop the duplex connection and shutdown(s) the socket. The disadvantage is shutdown() will not do the graceful shutdown of socket(s).
But for your requirement, use shutdown(). It will do.
see shutdown(2) and close(2) man pages more.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-22-2004 03:07 PM
тАО07-22-2004 03:07 PM
Re: How to reject a socket connection?
now, before you have called accept(), the remote's connect() call will have completed, couple that with connect() not doing any automatic retry, and that leaves two possibilities I can think of-
1) the client application code, having had the connection close gracefully before it could get any reply to any request may have decided to try connecting again. if the client is running on HP-UX, you can take a tusc system call trace to see that.
2) there were actually more than 9 pending connections so when you closed the 9th there was a 10th sitting there.
if you call shutdown() eventually you still must call close() or you will run out of file descriptors.
if you only want to handle 8 connections at a time, why not simply stop calling accept() (or even selecting on the listen socket) and let the connections remain in the listen queue?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-22-2004 04:50 PM
тАО07-22-2004 04:50 PM
Re: How to reject a socket connection?
My algorithm is something like below
initialize the listen socket
while (1) {
select on the listen socket for 100msec
if (activity) {
accept only if u have a free slot,
else reject the connect (by accept
and close)
}
select on each of the 'fd' of already accepted connections (if some connection is freed, then update the free list)
if (activity) then process each of fd for about 500msec or so
}
so, you would see that i am re-cycling the freed connections in my while loop.
Muthu's soln: i shud'nt be re-initializing a socket everytime only to 'reject' a connection, unless there is no other way, ofcourse.
Jones soln: Same answer for the shutdown part. Also, I am sure its not some 9th connection, 'coz I have only one client requesting connection after an 8th. But for the qn 'why not simply let the conn req q up in the listen socket' -- the only concern is that i am notifying the client that i dont have to accept its connection.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-23-2004 02:46 AM
тАО07-23-2004 02:46 AM
Re: How to reject a socket connection?
Apart from that, I'm not shure what to suggest apart from tripplechecking the client code and what it does on connection close.