MCPcopy Create free account
hub / github.com/Tencent/UnLua / meth_sendto

Function meth_sendto

Plugins/UnLuaExtensions/LuaSocket/Source/src/unixdgram.cpp:135–171  ·  view source on GitHub ↗

-------------------------------------------------------------------------*\ * Send data through unconnected unixdgram socket \*-------------------------------------------------------------------------*/

Source from the content-addressed store, hash-verified

133* Send data through unconnected unixdgram socket
134\*-------------------------------------------------------------------------*/
135static int meth_sendto(lua_State *L)
136{
137 p_unix un = (p_unix) auxiliar_checkclass(L, "unixdgram{unconnected}", 1);
138 size_t count, sent = 0;
139 const char *data = luaL_checklstring(L, 2, &count);
140 const char *path = luaL_checkstring(L, 3);
141 p_timeout tm = &un->tm;
142 int err;
143 struct sockaddr_un remote;
144 size_t len = strlen(path);
145
146 if (len >= sizeof(remote.sun_path)) {
147 lua_pushnil(L);
148 lua_pushstring(L, "path too long");
149 return 2;
150 }
151
152 memset(&remote, 0, sizeof(remote));
153 strcpy(remote.sun_path, path);
154 remote.sun_family = AF_UNIX;
155 timeout_markstart(tm);
156#ifdef UNIX_HAS_SUN_LEN
157 remote.sun_len = sizeof(remote.sun_family) + sizeof(remote.sun_len)
158 + len + 1;
159 err = socket_sendto(&un->sock, data, count, &sent, (SA *) &remote, remote.sun_len, tm);
160#else
161 err = socket_sendto(&un->sock, data, count, &sent, (SA *) &remote,
162 sizeof(remote.sun_family) + len, tm);
163#endif
164 if (err != IO_DONE) {
165 lua_pushnil(L);
166 lua_pushstring(L, unixdgram_strerror(err));
167 return 2;
168 }
169 lua_pushnumber(L, (lua_Number) sent);
170 return 1;
171}
172
173static int meth_receive(lua_State *L) {
174 p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1);

Callers

nothing calls this directly

Calls 8

auxiliar_checkclassFunction · 0.85
luaL_checklstringFunction · 0.85
lua_pushnilFunction · 0.85
lua_pushstringFunction · 0.85
timeout_markstartFunction · 0.85
unixdgram_strerrorFunction · 0.85
lua_pushnumberFunction · 0.85
socket_sendtoFunction · 0.70

Tested by

no test coverage detected