Skip to contentSkip to conversation

Socket hack question.

DISCUSSION Joel Eriksson 2 participants 2 messages Apr 18, 2001

lore
Share & tools
lore
#0 lore raw

Hello,

I am a kernel hacking newbie and am struggling to understand the networking subsystem. I would like to be able to add a systemcall, preferably asynchronous, that connects a socket with a filedescriptor (proxy(srcsd, dstfd)) so that everything received on srcsd is directly written to dstfd. The proxy should close when srcsd is closed or when a zero-size packet is sent (or something like that..).

I started digging in the source yesterday, and have read a little in "The Linux Kernel" document and a few others, but can't say I feel much wiser. :-) I was thinking about creating a custom "data_ready" function that I set for the socket to be forwarded (in "struct sock"), does this make sense? How would I go about to write the data to the destination file/socket descriptor?

I am of course fully aware that it is not of public interest and have certainly not intended to try getting it into the mainstream kernel. :-) I'm just going to use it for a web server I am developing that communicates with applications via sockets (UNIX domain for local apps and TCP for remote), portability is not an issue in this particular case. Another obvious use is for bouncers.

I would like to avoid the kernel -> userspace -> kernel copying of data just to forward a packet.. The web server should be able to scale up to a couple of thousands simultaneous connections without significant performance penalty, so I plan to use multiple processes or perhaps threads to avoid the bad scalability of select()/poll().

When I (or if I :-) get more proficient in kernel hacking I will perhaps try adding support for fully event-driven I/O handling. Or are there perhaps any similar patches available from somewhere already?

Signature · 1 line
Joel Eriksson
#1 lore raw
Quoted 8 lines · Joel Eriksson

Hello,

I am a kernel hacking newbie and am struggling to understand the networking subsystem. I would like to be able to add a systemcall, preferably asynchronous, that connects a socket with a filedescriptor (proxy(srcsd, dstfd)) so that everything received on srcsd is directly written to dstfd. The proxy should close when srcsd is closed or when a zero-size packet is sent (or something like that..).

That syscall already exists -- it's called sendfile.

-Andi