title: C UDP read and recv are breaking my code
body: <p>So I'm working with UDP sockets and poll(), trying to be able to wait for connections and read input at the same time, but I'm coming up with the weirdest error and I have no idea how to handle it. Here's the part of my code that's causing issues.</p>
  
  <pre><code>int n=1;   //set n =1 so that it can enter first loop
  
  while (1) {
    for(int j = 0; j &lt; 2; j++){
      printf("loop1\n");
      if(n&gt;0){
        printf("loop2\n");
        mlen = read(sd, buf, BSIZE);      
        //I would like to use read here, but I've tried both read and recvfrom
        //and both have the same issue \/ that's the other code I was trying
        //mlen = recvfrom(sd,buf,BSIZE,0,(struct sockaddr *)&amp;cad, &amp;fromlen);
        if(mlen&lt;0){
          perror("recvfrom");
          exit(1);
        }
  
        /* more code here that does stuff with buffer info */
      }
      else {
        perror("poll");
        exit(1);}
      }
    }
    n = poll(pollarr,2,-1);
    printf("now n is %d\n", n);
  }
  </code></pre>
  
  <p>So here's where it gets strange. When I run this code, it prints out loop1, but does not print loop2, even though I explicitly set n=1 at the beginning. I changed the loop1 print statement to "printf("now n is %d\n", n);" to see what was going on, and then it didn't print anything at all. </p>
  
  <p>To add to this mystery, this happens regardless of if I use read or recv, but when I comment out both of those my code enters both loops just fine.</p>
  
  <p>So, somehow both read and recv are preventing my program from running the way it should, before those lines are even reached. I have no clue what could be going on, and my best guess would be that it's some obscure C thing that I just don't know about. Does anyone know what's going wrong?</p>
  
  <p>If it matters, I think I'm using Linux. </p>