[BusyBox] Syslogd using select()
Gennady Feldman
gena01 at cachier.com
Wed Mar 7 01:19:53 UTC 2001
On Tue, 6 Mar 2001, Gennady Feldman wrote:
> --------------------[Code snippet]-------------------------
> for (fd = 0; (n_ready > 0) && (fd < FD_SETSIZE); fd++) {
> if (FD_ISSET (fd, &readfds)) {
>
> --n_ready;
>
> if (fd == sock_fd) {
>
> int conn;
> pid_t pid;
>
> if ((conn = accept (sock_fd,
> (struct sockaddr *) &sunx, &addrLength)) < 0) {
> perror_msg_and_die
> ("accept error");
> }
>
> pid = fork();
>
> if (pid < 0) {
> perror ("syslogd: fork");
> close (conn);
> continue;
> }
>
> if (pid == 0) {
> serveConnection (conn);
> close (conn);
> exit( TRUE);
> }
> close (conn);
> }
> }
> -------------------------------------------------------------------------
[Let's try this again.....]
----------------------------------------[Proposed Code]------------------
for (fd = 0; (n_ready > 0) && (fd < FD_SETSIZE); fd++) {
if (FD_ISSET (fd, &readfds)) {
--n_ready;
if (fd == sock_fd) {
int conn;
if ((conn = accept (sock_fd,
(struct sockaddr *) &sunx, &addrLength)) < 0) {
perror_msg_and_die
("accept error");
}
FD_SET(conn, &readfds);
}else{
serveConnection (fd);
close (fd);
FD_CLR(fd, &readfds);
} /* fd == sock_fd */
}/* FD_ISSET() */
}/* for */
-----------------------------------------------------------------------
P.S. The above snipet of code compiles, I just can't test it right now.
Will do some testing tomorrow. I would post a patch, but it's not ready
yet. Want to finish up this thing first before I submit a patch w/ all my
changes. Don't want to break somebody's busybox completely. Can somebody
look this over and maybe test this?
G.F.
More information about the busybox
mailing list