Powered by Invision Power Board


  Reply to this topicStart new topicStart Poll

> UX-Socket problem, server stuck on accept() when recovering
alon_2002
Posted: Apr 21 2005, 03:23 PM
Quote Post


Newbie
*

Group: Members
Posts: 1
Member No.: 938
Joined: 21-April 05



Hello.
I have a bug in my server UX-socket program which runs on linux with kernel 2.6.7.

the bug is that when I crash my program and start it up again (while the client is still running) the server gets stuck on the accept() function and cannot contnue.
I know the problem is not in the client, since it was tested already with other servers successfly. :huh: :huh:
Please Please help me, let me knoe what you can make of this:



here is the code from my server:


CODE


//1. open socket for client to connect
int sockfd;
if ((sockfd = socket(AF_UNIX,SOCK_STREAM,0))==-1){
 cerr << "Cannot allocate a free socket... Exiting.\n";
 exit (1);
}

struct sockaddr_un our_addr;
bzero((char *) &our_addr, sizeof(our_addr));
our_addr.sun_family=AF_UNIX;
strcpy(our_addr.sun_path, client_info.socket);
int servlen =strlen(our_addr.sun_path) + sizeof(our_addr.sun_family);

unlink(client_info.socket);

if (bind(sockfd,(struct sockaddr *)&our_addr,servlen) == -1) {
 cerr  << "Cannot bind the port. Exiting.\n";
 exit(1);
}

if (listen(sockfd,0) == -1) {
 cerr  << "Cannot listen the port. Exiting.\n";
 exit (1);
}


 

/* 2. connect */
   int fd;
 


int non_blocking_mode = 1;
int on = 1;




   struct sockaddr_un their_addr;
   int sun_size = sizeof(struct sockaddr_un);
   if ((fd=accept(sockfd, (struct sockaddr *)&their_addr,reinterpret_cast<socklen_t*>(&sun_size))) == -1){
 cerr <<  "Cannot accept the connection. Exiting.\n";
    exit (1);
   }




/* 3. make the fd NONBLOCK */
int val;
val=fcntl(fd,F_GETFL,0);
val |= O_NONBLOCK;
fcntl(fd,F_SETFL,val);

              .
              .
              .
              read() and write() stuff...

.
              .
              .
PMEmail Poster
Top
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
« Next Oldest | Programming/Languages | Next Newest »

Topic Options Reply to this topicStart new topicStart Poll

 



[ Script Execution time: 0.1638 ]   [ 12 queries used ]   [ GZIP Enabled ]




Partners: Cambridge Plus :: <Link Available> :: Server Room Temperature Monitor :: <Link Available>
Unix Man Pages / Linux Man Pages :: HiFi Forum :: SIP VoIP Phone & Provider Reviews :: UNIX/Linux Forum Archives

More info on advertising on Unix/Linux Forum