Thread: If two sockets attempt to send and recv at the same time will program lock up?

  1. #1
    Registered User
    Join Date
    Jul 2017
    Posts
    28

    If two sockets attempt to send and recv at the same time will program lock up?

    I have two sockets, which are running on my Linux board under localhost IPv6 (::1). I programmed the .so in C.

    If each socket is running in a separate loop and both sockets call the send() or the recv() socket function at the same time, will my program freeze because that is what is happening.

    I specified my sockets as non-blocking, but it still freezes.

    I tried running my code in one loop i.e. server send, client recv, client send, server recv, and that works. It only does not work if I run my code in parallel loops.

    Does anyone know why this might happen?

    Thanks.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Without seeing the code, it would be wild speculation at best.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jul 2017
    Posts
    28
    Quote Originally Posted by Salem View Post
    Without seeing the code, it would be wild speculation at best.
    Do you want me to post the LabVIEW code (block diagram code) that calls my library, or just the C .so library?

    I don't want to post LabVIEW code, if it does not fit here.

    Thanks.
    Last edited by JHugh; 08-10-2017 at 06:29 AM.

  4. #4
    Registered User
    Join Date
    Jul 2017
    Posts
    28
    It could be that I'm setting up a non-blocking socket wrong. Is this correct? I think I may be missing the argument in fcntl...

    I really need my company to buy me a good Linux C book... And, my terrible laptop won't let me cut and paste to this forum properly, so I have to reformat all my code...


    Code:
    if(fcntl(sockfd, F_SETFL, O_NONBLOCK) == -1) {
       *errnoOut = errno;
       return(-1);
    } else {
       printf("nonbloc val = %I", fcntl(sockfd, F_GETFL, O_NONBLOCK));
       *errnoOut = 0;
       return(sockfd);
    }

  5. #5
    Registered User
    Join Date
    Jul 2017
    Posts
    28
    Nevermind, I solved it. I was passing sockfd instead of newsockfd to fcntrl().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Send() and Recv()
    By Rodaxoleaux in forum Networking/Device Communication
    Replies: 0
    Last Post: 12-07-2011, 12:57 PM
  2. TCP/IP Sockets in C (problem with send() and recv(): how to loop them)
    By ferenczi in forum Networking/Device Communication
    Replies: 3
    Last Post: 11-18-2008, 07:38 AM
  3. Send/Recv
    By brietje698 in forum Networking/Device Communication
    Replies: 13
    Last Post: 12-13-2007, 10:16 PM
  4. send and recv
    By DeadManWalking in forum C Programming
    Replies: 1
    Last Post: 12-04-2005, 09:17 AM
  5. send/recv binary files using sockets in C++
    By dafatdude in forum Networking/Device Communication
    Replies: 14
    Last Post: 07-25-2004, 11:00 AM

Tags for this Thread