Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Programming Threads > accept()
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 2 Topic 4086 of 4146
Post > Topic >>

accept()

by Kristof Benes <chris@[EMAIL PROTECTED] > Oct 11, 2008 at 07:45 PM

Hi All,

I'm new to this newsgroup, and have only used threads in a very basic 
manner up to this point, but have been a C programmer for about 5-6 years.

I'm working on a project, its in C, on OpenBSD 4.3, using the system 
pthread library and system compiler (gcc 3.3.5 propolice).  The goal is 
to create a daemon process that listens on both a TCP socket and a UNIX 
socket eg. file and process incoming connections identically.  The 
thought was to, after daemonization to start two threads, each with 
their own listen loop, one for TCP and one for the UNIX domain socket. 
So I'm writing the TCP ****tion first and I get a strange condition. 
When I call accept instead of blocking, it actually aborts the program, 
no error message, gdb just returns and says "program terminated 
normally".  Having it just run not as a seperate thread, it works 
correctly.  Heres the code:

void init_sockets()
{
    pthread_t tcp_pt;

    if (get_config_int("tcp_listen_****t") > 0) {
       /*pthread_create(&tcp_pt,NULL,tcp_socket_loop,NULL);*/ << aborts
       tcp_socket_loop(NULL); << works
    }
}

void *tcp_socket_loop(void *junk)
{
    int sock = socket(AF_INET,SOCK_STREAM,0);
    int ****t = get_config_int("tcp_listen_****t");  << verified is 5555, 
which it is supposed to be
    struct sockaddr_in sa,ca;
    int cli_fd,cl;
    char buf[128];

    if (sock == -1) error_exit("socket() failed: %m");
    memset(&sa,0,sizeof(struct sockaddr_in));
    sa.sin_family = AF_INET;
    sa.sin_addr.s_addr = htonl(INADDR_ANY);
    sa.sin_****t = htons(****t);
    if (bind(sock,(struct sockaddr *)&sa,sizeof(struct sockaddr_in)) < 
0) error_exit("bind() failed: %m");
    snprintf(buf,sizeof(buf),"Listening on TCP ****t %d",****t); << it 
gets to this point, everything looks okay
    status_message(buf);
    listen(sock,10); << checked errno, was 0
    cli_fd = accept(sock,(struct sockaddr *)&ca,&cl); << program ends
here?
    return NULL; << never reaches this line in GDB
}

Is it a gdb problem?  Is there some caveat to accept inside of a thread 
that I dont know about?  Any help would be greatly appreciated.
 




 2 Posts in Topic:
accept()
Kristof Benes <chris@[  2008-10-11 19:45:25 
Re: accept()
Kristof Benes <chris@[  2008-10-11 19:58:50 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Nov 22 9:40:24 CST 2008.