|
34 | 34 |
|
35 | 35 | #define NET_BUF_SIZE 32*1024
|
36 | 36 |
|
| 37 | +enum Transport_Types { |
| 38 | + TRANSPORT_TCP, |
| 39 | + TRANSPORT_UDP |
| 40 | +}; |
| 41 | + |
37 | 42 | /***********************************************************************
|
38 | 43 | **
|
39 | 44 | */ static void Ret_Query_Net(REBSER *port, REBREQ *sock, REBVAL *ret)
|
|
86 | 91 | OS_FREE(nsock); // allocated by dev_net.c (MT issues?)
|
87 | 92 | }
|
88 | 93 |
|
89 |
| - |
90 | 94 | /***********************************************************************
|
91 | 95 | **
|
92 |
| -*/ static int TCP_Actor(REBVAL *ds, REBSER *port, REBCNT action) |
| 96 | +*/ static int Transport_Actor(REBVAL *ds, REBSER *port, REBCNT action, enum Transport_Types proto) |
93 | 97 | /*
|
94 | 98 | ***********************************************************************/
|
95 | 99 | {
|
|
109 | 113 | refs = 0;
|
110 | 114 |
|
111 | 115 | sock = Use_Port_State(port, RDI_NET, sizeof(*sock));
|
| 116 | + if (proto == TRANSPORT_UDP) { |
| 117 | + SET_FLAG(sock->modes, RST_UDP); |
| 118 | + } |
112 | 119 | //Debug_Fmt("Sock: %x", sock);
|
113 | 120 | spec = OFV(port, STD_PORT_SPEC);
|
114 | 121 | if (!IS_OBJECT(spec)) Trap0(RE_INVALID_PORT);
|
|
189 | 196 | // Read data into a buffer, expanding the buffer if needed.
|
190 | 197 | // If no length is given, program must stop it at some point.
|
191 | 198 | refs = Find_Refines(ds, ALL_READ_REFS);
|
192 |
| - if (!GET_FLAG(sock->state, RSM_CONNECT)) Trap_Port(RE_NOT_CONNECTED, port, -15); |
| 199 | + if (!GET_FLAG(sock->modes, RST_UDP) |
| 200 | + && !GET_FLAG(sock->state, RSM_CONNECT)) |
| 201 | + Trap_Port(RE_NOT_CONNECTED, port, -15); |
193 | 202 |
|
194 | 203 | // Setup the read buffer (allocate a buffer if needed):
|
195 | 204 | arg = OFV(port, STD_PORT_DATA);
|
|
214 | 223 | // The lower level write code continues until done.
|
215 | 224 |
|
216 | 225 | refs = Find_Refines(ds, ALL_WRITE_REFS);
|
217 |
| - if (!GET_FLAG(sock->state, RSM_CONNECT)) Trap_Port(RE_NOT_CONNECTED, port, -15); |
| 226 | + if (!GET_FLAG(sock->modes, RST_UDP) |
| 227 | + && !GET_FLAG(sock->state, RSM_CONNECT)) |
| 228 | + Trap_Port(RE_NOT_CONNECTED, port, -15); |
218 | 229 |
|
219 | 230 | // Determine length. Clip /PART to size of string if needed.
|
220 | 231 | spec = D_ARG(2);
|
|
293 | 304 | return R_RET;
|
294 | 305 | }
|
295 | 306 |
|
| 307 | +/*********************************************************************** |
| 308 | +** |
| 309 | +*/ static int TCP_Actor(REBVAL *ds, REBSER *port, REBCNT action) |
| 310 | +/* |
| 311 | +***********************************************************************/ |
| 312 | +{ |
| 313 | + return Transport_Actor(ds, port, action, TRANSPORT_TCP); |
| 314 | +} |
| 315 | + |
| 316 | +/*********************************************************************** |
| 317 | +** |
| 318 | +*/ static int UDP_Actor(REBVAL *ds, REBSER *port, REBCNT action) |
| 319 | +/* |
| 320 | +***********************************************************************/ |
| 321 | +{ |
| 322 | + return Transport_Actor(ds, port, action, TRANSPORT_UDP); |
| 323 | +} |
296 | 324 |
|
297 | 325 | /***********************************************************************
|
298 | 326 | **
|
|
302 | 330 | {
|
303 | 331 | Register_Scheme(SYM_TCP, 0, TCP_Actor);
|
304 | 332 | }
|
| 333 | +/*********************************************************************** |
| 334 | +** |
| 335 | +*/ void Init_UDP_Scheme(void) |
| 336 | +/* |
| 337 | +***********************************************************************/ |
| 338 | +{ |
| 339 | + Register_Scheme(SYM_UDP, 0, UDP_Actor); |
| 340 | +} |
0 commit comments