Redirecting socket output to a file
Hi,
I need help on these questions: a) How do I redirect the data that flows through a socket to a file, without cutting the flow? b) Can a file number be returned from a function, and when I do a read() or a write() call, will it remain the same? (see below). What I was thinking for the first question is to: - create a pipe with the pipe() system call - make the file descriptor of the "write" side of the pipe to be the same as the file descriptor of the socket - create a file with the O_ASYNC flag, in so a way that when there's something to be written to the file, a signal is sent. - make the file descriptor of the "read" side of the pipe to be the same as the file descriptor of this file. But there are two things: a) Is there a better approach? b) How do I open() a file that has the file descriptor number I want? What I was thinking for the second question was: Code:
void mkchild(int fd) Thanks in advance. |
Quote:
You might also want to check out: man 2 dup2 |
All times are GMT -5. The time now is 10:43 PM. |