Changeset 4427

Show
Ignore:
Timestamp:
02/07/07 21:11:06
Author:
trondeau
Message:

minor fixes: data types, variable names, some handling

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_sink.cc

    r4355 r4427  
    8484 
    8585  // Turn on reuse address 
    86   bool opt_val = true; 
     86  int opt_val = true; 
    8787  if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (void*)&opt_val, sizeof(int)) == -1) { 
    8888    perror("SO_REUSEADDR"); 
     
    132132                   gr_vector_void_star &output_items) 
    133133{ 
    134   char *in = (char *) input_items[0]; 
    135   ssize_t bytes=0, bytes_sent=0, bytes_to_send=0; 
     134  const char *in = (const char *) input_items[0]; 
     135  ssize_t r=0, bytes_sent=0, bytes_to_send=0; 
    136136  ssize_t total_size = noutput_items*d_itemsize; 
    137137 
     
    141141 
    142142  while(bytes_sent <  total_size) { 
    143     //bytes_to_send = (bytes_sent+d_mtu < total_size ? d_mtu : total_size-bytes_sent); 
    144143    bytes_to_send = std::min(d_mtu, (total_size-bytes_sent)); 
    145144   
    146     bytes = send(d_socket, (in+bytes_sent), bytes_to_send, 0); 
    147     bytes_sent += bytes; 
     145    r = send(d_socket, (in+bytes_sent), bytes_to_send, 0); 
     146    // FIX ERROR HANDLING 
     147    bytes_sent += r; 
    148148     
    149149    #if SNK_VERBOSE 
  • gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_sink.h

    r4355 r4427  
    3535 * \brief Write stream to an Udp port (over UDP). 
    3636 * \ingroup sink 
     37 * source 
     38 * destination 
     39 * domain name 
     40 * mtu size (default=1500) 
    3741 */ 
    3842 
     
    8892  void close(); 
    8993 
    90   /*! \brief set the MTU of the socket */ 
    91   void set_mtu(int mtu) { d_mtu = mtu; } 
    92  
    9394  /*! \brief return the MTU of the socket */ 
    9495  int mtu() { return d_mtu; } 
  • gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_sink.i

    r4355 r4427  
    4040  bool open(); 
    4141  void close(); 
    42   void set_mtu(int mtu) { d_mtu = mtu; } 
    4342  int mtu() { return d_mtu; } 
    4443 
  • gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.cc

    r4356 r4427  
    7474 
    7575  // Turn on reuse address 
    76   bool opt_val = true
     76  int opt_val = 1
    7777  if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (void*)&opt_val, sizeof(int)) == -1) { 
    7878    perror("SO_REUSEADDR"); 
     
    127127{ 
    128128  char *out = (char *) output_items[0]; 
    129   ssize_t bytes_to_receive=0, bytes_received=0, bytes=0; 
     129  ssize_t r=0, nbytes=0, bytes_received=0; 
    130130  ssize_t total_bytes = (ssize_t)(d_itemsize*noutput_items); 
    131131 
     
    136136  // Remove items from temp buffer if they are in there 
    137137  if(d_residual) { 
    138     bytes_to_receive = std::min(d_residual, total_bytes); 
    139     memcpy(out, d_temp_buff+d_temp_offset, bytes_to_receive); 
    140     bytes_received = bytes_to_receive
     138    nbytes = std::min(d_residual, total_bytes); 
     139    memcpy(out, d_temp_buff+d_temp_offset, nbytes); 
     140    bytes_received = nbytes
    141141 
    142142    #if SRC_VERBOSE 
    143     printf("\tTemp buff size: %d  offset: %d (bytes_to_receive: %d) (noutput_items: %d)\n",  
     143    printf("\tTemp buff size: %d  offset: %d (bytes_received: %d) (noutput_items: %d)\n",  
    144144           d_residual, d_temp_offset, bytes_received, noutput_items); 
    145145    #endif 
     
    149149     
    150150    // Update indexing of amount of bytes left in the buffer 
    151     d_residual -= bytes_to_receive
     151    d_residual -= nbytes
    152152    d_temp_offset = d_temp_offset+d_residual; 
    153153  } 
    154154 
    155   while((bytes_received < total_bytes) && (bytes>-1)) { 
     155  while(bytes_received < total_bytes) { 
    156156    // get the data into our output buffer and record the number of bytes 
    157157    // This is a non-blocking call with a timeout set in the constructor 
    158     bytes = recv(d_socket, d_temp_buff, d_mtu, 0);  // get the entire MTU or the rest of what's available 
     158    r = recv(d_socket, d_temp_buff, d_mtu, 0);  // get the entire MTU or the rest of what's available 
    159159 
    160160    // Check if there was a problem; forget it if the operation just timed out 
    161     if(bytes == -1) { 
     161    if(r == -1) { 
    162162      if(errno == EAGAIN) {  // handle non-blocking call timeout 
    163163        #if SRC_VERBOSE 
    164164        printf("UDP receive timed out\n");  
    165165        #endif 
    166         break
     166        continue
    167167      } 
    168168      else { 
     
    173173    else { 
    174174      // Calculate the number of bytes we can take from the buffer in this call 
    175       bytes_to_receive = std::min(bytes, total_bytes-bytes_received); 
     175      nbytes = std::min(r, total_bytes-bytes_received); 
    176176 
    177177      // copy the number of bytes we want to look at here 
    178       memcpy(out, d_temp_buff, bytes_to_receive);     
    179  
    180       d_residual=bytes-bytes_to_receive;                      // save the number of bytes stored 
    181       d_temp_offset=bytes_to_receive;                         // reset buffer index 
     178      memcpy(out, d_temp_buff, nbytes);     
     179 
     180      d_residual = r - nbytes;                      // save the number of bytes stored 
     181      d_temp_offset=nbytes;                         // reset buffer index 
    182182 
    183183      // keep track of the total number of bytes received 
    184       bytes_received += bytes_to_receive
     184      bytes_received += nbytes
    185185 
    186186      // increment the pointer 
    187       out += bytes_to_receive; 
     187      out += nbytes; 
     188 
     189      // break here 
     190      // Immediately return when data comes in 
    188191    } 
    189192 
    190193    #if SNK_VERBOSE 
    191     printf("\tbytes received: %d bytes (bytes_to_receive: %d)\n", bytes, bytes_to_receive); 
     194    printf("\tbytes received: %d bytes (nbytes: %d)\n", bytes, nbytes); 
    192195    #endif 
    193196  } 
     
    197200  #endif 
    198201 
     202  // return biggest legal increment (not fractional) 
    199203  return noutput_items; 
    200204} 
     205 
  • gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.h

    r4355 r4427  
    8080  void close(); 
    8181 
    82   /*! \brief set the MTU of the socket */ 
    83   void set_mtu(int mtu) { d_mtu = mtu; } 
    84  
    8582  /*! \brief return the MTU of the socket */ 
    8683  int mtu() { return d_mtu; } 
  • gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.i

    r4355 r4427  
    3838  bool open(); 
    3939  void close(); 
    40   void set_mtu(int mtu) { d_mtu = mtu; } 
    4140  int mtu() { return d_mtu; } 
    4241