diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/udp.c | 21 |
1 files changed, 21 insertions, 0 deletions
| @@ -189,6 +189,27 @@ static int meth_sendto(lua_State *L) { | |||
| 189 | lua_pushstring(L, gai_strerror(err)); | 189 | lua_pushstring(L, gai_strerror(err)); |
| 190 | return 2; | 190 | return 2; |
| 191 | } | 191 | } |
| 192 | |||
| 193 | /* create socket if on first sendto if AF_UNSPEC was set */ | ||
| 194 | if (udp->family == AF_UNSPEC && udp->sock == SOCKET_INVALID) { | ||
| 195 | struct addrinfo *ap; | ||
| 196 | const char *errstr = NULL; | ||
| 197 | for (ap = ai; ap != NULL; ap = ap->ai_next) { | ||
| 198 | errstr = inet_trycreate(&udp->sock, ap->ai_family, SOCK_DGRAM, 0); | ||
| 199 | if (errstr == NULL) { | ||
| 200 | socket_setnonblocking(&udp->sock); | ||
| 201 | udp->family = ap->ai_family; | ||
| 202 | break; | ||
| 203 | } | ||
| 204 | } | ||
| 205 | if (errstr != NULL) { | ||
| 206 | lua_pushnil(L); | ||
| 207 | lua_pushstring(L, errstr); | ||
| 208 | freeaddrinfo(ai); | ||
| 209 | return 2; | ||
| 210 | } | ||
| 211 | } | ||
| 212 | |||
| 192 | timeout_markstart(tm); | 213 | timeout_markstart(tm); |
| 193 | err = socket_sendto(&udp->sock, data, count, &sent, ai->ai_addr, | 214 | err = socket_sendto(&udp->sock, data, count, &sent, ai->ai_addr, |
| 194 | (socklen_t) ai->ai_addrlen, tm); | 215 | (socklen_t) ai->ai_addrlen, tm); |
