LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 12-02-2011, 06:51 AM   #1
_gg
LQ Newbie
 
Registered: Dec 2011
Posts: 2

Rep: Reputation: Disabled
Question Temporarily release socket FD while keeping connection alive...


Hi,

I have TCP/IPv4 listen server.
A client connects to it, sends some data and then connection is inactive, but stays alive.
From now, client sends no more data.
After some time, by some third-party notification, server replies to the client and that connection is closed.

`accept()` creates file descriptor and while that connection is alive it occupies that fd.
My server should be capable to hold big amount of such parallel connections, even much more than file descriptor limit.

The solution can be: temporarily release socket file descriptor for that connection after receiving data and manually assign fd to that existing connection before reply and then close.

How can we solve that?

---
1) If we might somehow change `socket_type` for open socket file descriptor, we could do:
Code:
listen(server, 20);
s = accept(...);
recv(s, request, sizeof(request));
change_socket_type(s, SOCK_DGRAM);
close(s); // this won't send TCP FIN, just release `s` fd
...
s = socket(AF_INET, SOCK_DGRAM, 0);
bind(...); // set local endpoint
connect(...); // set remote endpoint
change_socket_type(s, SOCK_STREAM); // restore fd for existing
   // TCP connection without sending SYN, ACK
send(s, ...); // reply to client
close(s); // send TCP FIN and close connection
How to do this, if possible?

2) Emulate all TCP layer by using RAW sockets. Thus we can perform low-level TCP actions. The only problem is to make listen server, so kernel doesn't manage listening port and replying "Connection refused". How about TCP listening with `backlog=0` and not accepting the incoming connections?
Code:
listen(server, 0); // minimal queue not to occupy memory
...
recv(raw_server, ...); // sniff for TCP connection request
...
sendto(raw_server, ...); // manage TCP via RAW
Won't kernel interfere our sniffer, while client is infinitely waiting for accept?
Maybe you have some other idea how to do this?

Taras

(thread is copied from Linux - Server)
 
Old 12-03-2011, 05:39 AM   #2
TimothyEBaldwin
Member
 
Registered: Mar 2009
Posts: 249

Rep: Reputation: 27
Increase the file descriptor limit and/or modify the protocol not to leave connections idle for so long. In Linux the file descriptor limit can be increased to 2,147,483,648.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Temporarily release socket FD while keeping connection alive _gg Programming 1 12-03-2011 01:32 PM
linux programing: checking of socket connection is alive tilman1 Linux - Networking 1 09-11-2011 09:51 PM
keeping OpenSuSe 10.2 alive SolarisZen SUSE / openSUSE 10 12-22-2009 01:40 PM
Keeping the connection alive? NonSumPisces Linux - Networking 2 07-08-2004 06:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 03:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration