I found a problem with the implementation of threads, this is strange for me. Maybe some of you can explain this to me, it would be great.
I am working on a proxy server, a program (on different machines) that receives packets through eth0 and sends it through ath0 (wireless) to another machine that does the same. Actually, I'm not at all sure what causes my problem, because I'm new to Linux and programming.
I run two threads
- one listens (socket) on eth0 for incoming packets and sends it through ath0 (also socket)
- and another thread listens on ath0 and sends through eth0.
If I use streams, I get this error:
sh-2.05b
If I use fork (), the program works as expected. Can someone explain this behavior to me?
Just to show the sender implementation, here is a snippet of code:
while(keep_going) { memset(&buffer[0], '\0', sizeof(buffer)); recvlen = recvfrom(sockfd_in, buffer, BUFLEN, 0, (struct sockaddr *) &incoming, &ilen); if(recvlen < 0) { perror("something went wrong / incoming\n"); exit(-1); } strcpy(msg, buffer); buflen = strlen(msg); sentlen = ath_sendto(sfd, &btpinfo, &addrnwh, &nwh, buflen, msg, &selpv2, &depv); if(sentlen == E_ERR) { perror("Failed to send network header packet.\n"); exit(-1); } }
UPDATE : my main file, starting a thread or processes (fork)
int main(void) { port_config pConfig; memset(&pConfig, 0, sizeof(pConfig)); pConfig.inPort = 2002; pConfig.outPort = 2003; pid_t retval = fork(); if(retval == 0) { // child process pc2wsuThread((void *) &pConfig); } else if (retval < 0) { perror("fork not successful\n"); } else { // parent process wsu2pcThread((void *) &pConfig); } /* wint8 rc1, rc2 = 0; pthread_t pc2wsu; pthread_t wsu2pc; rc1 = pthread_create(&pc2wsu, NULL, pc2wsuThread, (void *) &pConfig); rc2 = pthread_create(&wsu2pc, NULL, wsu2pcThread, (void *) &pConfig); if(rc1) { printf("error: pthread_create() is %d\n", rc1); return(-1); } if(rc2) { printf("error: pthread_create() is %d\n", rc2); return(-1); } pthread_join(pc2wsu, NULL); pthread_join(wsu2pc, NULL); */ return 0; }
Does it help?
update 05/30/2011
-sh-2.05b
Still get the interrupted system call, as you can see above. I blocked all signals as follows:
sigset_t signal_mask; sigfillset(&signal_mask); sigprocmask(SIG_BLOCK, &signal_mask, NULL);
Two threads work on the same interfaces, but on different ports. It seems that the problem remains in the same place (please find it in the first code snippet). I cannot go further and not enough to know how to solve this problem. Maybe some of you can help me here again.
Thanks in advance.