-------------------------------------------------------------------------*\ * Send data through unconnected unixdgram socket \*-------------------------------------------------------------------------*/
| 133 | * Send data through unconnected unixdgram socket |
| 134 | \*-------------------------------------------------------------------------*/ |
| 135 | static 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 | |
| 173 | static int meth_receive(lua_State *L) { |
| 174 | p_unix un = (p_unix) auxiliar_checkgroup(L, "unixdgram{any}", 1); |
nothing calls this directly
no test coverage detected