Changeset 470 for trunk/thune/net.c
- Timestamp:
- 09/03/07 18:33:32 (15 months ago)
- Files:
-
- 1 modified
-
trunk/thune/net.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/thune/net.c
r458 r470 173 173 /* 174 174 ('udp port -- port!) 175 ('udp [port host host-port ] -- port!)175 ('udp [port host host-port 'nowait] -- port!) 176 176 177 177 The UPortDevice open method must return the following: … … 184 184 struct sockaddr_in addr; 185 185 int port = 0; 186 int blocking = 1; 187 UCell* initAddr = 0; 186 188 UCell* spec = 0; 187 189 UCell* res = ur_s_prev(tos); … … 204 206 UCell* end; 205 207 int hostPort; 208 UAtom atom_nb = 0; 206 209 UBlock* blk = ur_block(spec); 207 210 … … 221 224 else if( ur_is(it, UT_STRING) ) 222 225 { 223 spec = it; 226 initAddr = it; 227 } 228 else if( ur_is(it, UT_WORD) ) 229 { 230 if( ! atom_nb ) 231 atom_nb = ur_intern( "nowait", 6 ); 232 if( ur_atom(it) == atom_nb ) 233 blocking = 0; 224 234 } 225 235 ++it; 226 236 } 227 237 228 if( (! hostPort) || (! ur_is(spec, UT_STRING)) ) 229 { 230 ur_throwErr( UR_ERR_DATATYPE, "Invalid socket spec" ); 231 return -1; 232 } 233 234 if( ! _makeAddrName( &addr, ur_cstring(ut,spec), hostPort ) ) 235 { 236 ur_throwErr( UR_ERR_ACCESS, "gethostbyname failed" ); 237 return -1; 238 if( initAddr && hostPort ) 239 { 240 if( ! _makeAddrName( &addr, ur_cstring(ut,initAddr), hostPort ) ) 241 { 242 ur_throwErr( UR_ERR_ACCESS, "gethostbyname failed" ); 243 return -1; 244 } 238 245 } 239 246 } … … 242 249 UCell* val; 243 250 int socket; 244 int block = 1;245 251 246 252 if( ! ur_userAllows( ut, "Open socket on port %d", port ) ) … … 250 256 } 251 257 252 socket = _openUdpSocket( ut, port, block );258 socket = _openUdpSocket( ut, port, blocking ); 253 259 if( socket < 0 ) 254 260 return -1; … … 264 270 265 271 binN = ur_makeBinary( sizeof(struct sockaddr), &bin ); 266 if( spec)272 if( initAddr ) 267 273 { 268 274 bin->used = sizeof(addr);
