0

In Linux, using sendfile you can directly transfer file out to a socket.

But let's say we have two server socket, we want to the output of the first one to go out to the second one.

How to do that? Instead of

data=sock1.read()
sock2.write(data)
Yichuan Wang
  • 723
  • 8
  • 15

1 Answers1

0

I believe dup2 will work

spraff
  • 32,570
  • 22
  • 121
  • 229
  • what? how? dup2 duplicates file descriptors. The question is `we have two server socket, we want to the output of the first one to go out to the second one` – sehe Sep 06 '11 at 10:27
  • Sockets *are* file descriptors. After `dup2` whenever someone writes to the first one it's as if they wrote to the second. In this situation there is no "output from the first one", it collapses completely. – spraff Sep 06 '11 at 10:30
  • Show how it works. If both sockets are under the process' control then obviously there would be no problem eliminating the intermediate transfer? – sehe Sep 06 '11 at 11:01