Changeset 4427
- Timestamp:
- 02/07/07 21:11:06
- Files:
-
- gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_sink.cc (modified) (3 diffs)
- gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_sink.h (modified) (2 diffs)
- gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_sink.i (modified) (1 diff)
- gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.cc (modified) (6 diffs)
- gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.h (modified) (1 diff)
- gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.i (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_sink.cc
r4355 r4427 84 84 85 85 // Turn on reuse address 86 boolopt_val = true;86 int opt_val = true; 87 87 if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (void*)&opt_val, sizeof(int)) == -1) { 88 88 perror("SO_REUSEADDR"); … … 132 132 gr_vector_void_star &output_items) 133 133 { 134 c har *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; 136 136 ssize_t total_size = noutput_items*d_itemsize; 137 137 … … 141 141 142 142 while(bytes_sent < total_size) { 143 //bytes_to_send = (bytes_sent+d_mtu < total_size ? d_mtu : total_size-bytes_sent);144 143 bytes_to_send = std::min(d_mtu, (total_size-bytes_sent)); 145 144 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; 148 148 149 149 #if SNK_VERBOSE gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_sink.h
r4355 r4427 35 35 * \brief Write stream to an Udp port (over UDP). 36 36 * \ingroup sink 37 * source 38 * destination 39 * domain name 40 * mtu size (default=1500) 37 41 */ 38 42 … … 88 92 void close(); 89 93 90 /*! \brief set the MTU of the socket */91 void set_mtu(int mtu) { d_mtu = mtu; }92 93 94 /*! \brief return the MTU of the socket */ 94 95 int mtu() { return d_mtu; } gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_sink.i
r4355 r4427 40 40 bool open(); 41 41 void close(); 42 void set_mtu(int mtu) { d_mtu = mtu; }43 42 int mtu() { return d_mtu; } 44 43 gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.cc
r4356 r4427 74 74 75 75 // Turn on reuse address 76 bool opt_val = true;76 int opt_val = 1; 77 77 if(setsockopt(d_socket, SOL_SOCKET, SO_REUSEADDR, (void*)&opt_val, sizeof(int)) == -1) { 78 78 perror("SO_REUSEADDR"); … … 127 127 { 128 128 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; 130 130 ssize_t total_bytes = (ssize_t)(d_itemsize*noutput_items); 131 131 … … 136 136 // Remove items from temp buffer if they are in there 137 137 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; 141 141 142 142 #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", 144 144 d_residual, d_temp_offset, bytes_received, noutput_items); 145 145 #endif … … 149 149 150 150 // Update indexing of amount of bytes left in the buffer 151 d_residual -= bytes_to_receive;151 d_residual -= nbytes; 152 152 d_temp_offset = d_temp_offset+d_residual; 153 153 } 154 154 155 while( (bytes_received < total_bytes) && (bytes>-1)) {155 while(bytes_received < total_bytes) { 156 156 // get the data into our output buffer and record the number of bytes 157 157 // 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 available158 r = recv(d_socket, d_temp_buff, d_mtu, 0); // get the entire MTU or the rest of what's available 159 159 160 160 // Check if there was a problem; forget it if the operation just timed out 161 if( bytes== -1) {161 if(r == -1) { 162 162 if(errno == EAGAIN) { // handle non-blocking call timeout 163 163 #if SRC_VERBOSE 164 164 printf("UDP receive timed out\n"); 165 165 #endif 166 break;166 continue; 167 167 } 168 168 else { … … 173 173 else { 174 174 // 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); 176 176 177 177 // 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 stored181 d_temp_offset= bytes_to_receive; // reset buffer index178 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 182 182 183 183 // keep track of the total number of bytes received 184 bytes_received += bytes_to_receive;184 bytes_received += nbytes; 185 185 186 186 // increment the pointer 187 out += bytes_to_receive; 187 out += nbytes; 188 189 // break here 190 // Immediately return when data comes in 188 191 } 189 192 190 193 #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); 192 195 #endif 193 196 } … … 197 200 #endif 198 201 202 // return biggest legal increment (not fractional) 199 203 return noutput_items; 200 204 } 205 gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.h
r4355 r4427 80 80 void close(); 81 81 82 /*! \brief set the MTU of the socket */83 void set_mtu(int mtu) { d_mtu = mtu; }84 85 82 /*! \brief return the MTU of the socket */ 86 83 int mtu() { return d_mtu; } gnuradio/branches/developers/trondeau/udp/gnuradio-core/src/lib/io/gr_udp_source.i
r4355 r4427 38 38 bool open(); 39 39 void close(); 40 void set_mtu(int mtu) { d_mtu = mtu; }41 40 int mtu() { return d_mtu; } 42 41
