Commit 72ccba0e authored by Natanael Copa's avatar Natanael Copa

main/lua-socket: fix udp socket on first sendto

ref #6603

sent upstream: https://github.com/diegonehab/luasocket/pull/206
parent 8e89e1e3
From 3041a808c3797e3c87272d71666e7b2f7c7a9f46 Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Wed, 25 Jan 2017 12:43:29 +0100
Subject: [PATCH] Create socket on first sendto if family agnostic udp() was
used
Create socket and set family on first sendto() if udp() was created
without address family.
Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
---
src/udp.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/src/udp.c b/src/udp.c
index ec97252..605c195 100644
--- a/src/udp.c
+++ b/src/udp.c
@@ -189,6 +189,27 @@ static int meth_sendto(lua_State *L) {
lua_pushstring(L, gai_strerror(err));
return 2;
}
+
+ /* create socket if on first sendto if AF_UNSPEC was set */
+ if (udp->family == AF_UNSPEC && udp->sock == SOCKET_INVALID) {
+ struct addrinfo *ap;
+ const char *errstr = NULL;
+ for (ap = ai; ap != NULL; ap = ap->ai_next) {
+ errstr = inet_trycreate(&udp->sock, ap->ai_family, SOCK_DGRAM, 0);
+ if (errstr == NULL) {
+ socket_setnonblocking(&udp->sock);
+ udp->family = ap->ai_family;
+ break;
+ }
+ }
+ if (errstr != NULL) {
+ lua_pushnil(L);
+ lua_pushstring(L, errstr);
+ freeaddrinfo(ai);
+ return 2;
+ }
+ }
+
timeout_markstart(tm);
err = socket_sendto(&udp->sock, data, count, &sent, ai->ai_addr,
(socklen_t) ai->ai_addrlen, tm);
--
2.11.0
......@@ -4,7 +4,7 @@ _luaversions="5.1 5.2 5.3"
pkgname=lua-socket
_name=luasocket
pkgver=3.0_rc1_git20160306
pkgrel=1
pkgrel=2
_ver=${pkgver%_git*}
_ver=${_ver/_rc/-rc}
pkgdesc="Networking library for Lua"
......@@ -22,6 +22,7 @@ done
source="luasocket-$_ver.tar.gz::https://github.com/diegonehab/luasocket/archive/v$_ver.tar.gz
git.patch
lua-cflags.patch
0001-Create-socket-on-first-sendto-if-family-agnostic-udp.patch
"
# default_prepare assumes $_builddir
......@@ -67,10 +68,13 @@ done
md5sums="08bd2f265b244eb4bf5c2c36bf89b759 luasocket-3.0-rc1.tar.gz
44c07dc3dd311541a50b21aaa40e36d7 git.patch
d4319e4a20d476ea8d77a3421fca1808 lua-cflags.patch"
d4319e4a20d476ea8d77a3421fca1808 lua-cflags.patch
f91f7da1120e0c9f24d7df1fa31f2576 0001-Create-socket-on-first-sendto-if-family-agnostic-udp.patch"
sha256sums="8b67d9b5b545e1b694753dab7bd6cdbc24c290f2b21ba1e14c77b32817ea1249 luasocket-3.0-rc1.tar.gz
414cfe53e4455fc2b416779d5eaa3ade6d97c01fa62dbffb6c9d4d4ad84bdd76 git.patch
77d77fe688b27ae51bcf9d3ae51d43141ab85d95fd322b3904b55dbc76900418 lua-cflags.patch"
77d77fe688b27ae51bcf9d3ae51d43141ab85d95fd322b3904b55dbc76900418 lua-cflags.patch
f8ef57a31c95076438f22eccfbbae16e8767033269fd748dce0d0f919c8d660b 0001-Create-socket-on-first-sendto-if-family-agnostic-udp.patch"
sha512sums="f6efce259aaacaa11472911471f8a13b118fe009b8953a82c6aa18b9ec829cd1293180904e56935cb130d36d267e3f27c91db2d78e03f7488f3e100571ed0540 luasocket-3.0-rc1.tar.gz
45c80e488fedc879f0217bc8a654d80da003039f5d1ff21b0dea0eb769151787dbe793e44a3dfd72cb07ff2697eceaf4fc7b55b4634cd170fa71281f19f025a5 git.patch
fb482ad22b5caa2054b25c86edc01d1a666035930f6b55e7d12704dd78b9c31343c39eab5f13958941180d819aa37470c75fe27f1b206a4b431fb589663e2685 lua-cflags.patch"
fb482ad22b5caa2054b25c86edc01d1a666035930f6b55e7d12704dd78b9c31343c39eab5f13958941180d819aa37470c75fe27f1b206a4b431fb589663e2685 lua-cflags.patch
c45a12e17771a1b3b71154b5415421f524cd10b7969b4649a5f37b652cdc826721e117edb8fe64758d3520e59946e2f755b814f72cbb39ff42bf59bbcf9a64e9 0001-Create-socket-on-first-sendto-if-family-agnostic-udp.patch"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment