Skip to content

Commit 6adf543

Browse files
committed
Add low priority list to socket send buffer
1 parent 0279144 commit 6adf543

File tree

6 files changed

+192
-35
lines changed

6 files changed

+192
-35
lines changed

Diff for: lualib-src/lua-socket.c

+24-7
Original file line numberDiff line numberDiff line change
@@ -402,27 +402,43 @@ llisten(lua_State *L) {
402402
return 1;
403403
}
404404

405-
static int
406-
lsend(lua_State *L) {
407-
struct skynet_context * ctx = lua_touserdata(L, lua_upvalueindex(1));
408-
int id = luaL_checkinteger(L, 1);
405+
static void *
406+
get_buffer(lua_State *L, int *sz) {
409407
void *buffer;
410-
int sz;
411408
if (lua_isuserdata(L,2)) {
412409
buffer = lua_touserdata(L,2);
413-
sz = luaL_checkinteger(L,3);
410+
*sz = luaL_checkinteger(L,3);
414411
} else {
415412
size_t len = 0;
416413
const char * str = luaL_checklstring(L, 2, &len);
417414
buffer = malloc(len);
418415
memcpy(buffer, str, len);
419-
sz = (int)len;
416+
*sz = (int)len;
420417
}
418+
return buffer;
419+
}
420+
421+
static int
422+
lsend(lua_State *L) {
423+
struct skynet_context * ctx = lua_touserdata(L, lua_upvalueindex(1));
424+
int id = luaL_checkinteger(L, 1);
425+
int sz = 0;
426+
void *buffer = get_buffer(L, &sz);
421427
int err = skynet_socket_send(ctx, id, buffer, sz);
422428
lua_pushboolean(L, !err);
423429
return 1;
424430
}
425431

432+
static int
433+
lsendlow(lua_State *L) {
434+
struct skynet_context * ctx = lua_touserdata(L, lua_upvalueindex(1));
435+
int id = luaL_checkinteger(L, 1);
436+
int sz = 0;
437+
void *buffer = get_buffer(L, &sz);
438+
skynet_socket_send_lowpriority(ctx, id, buffer, sz);
439+
return 0;
440+
}
441+
426442
static int
427443
lbind(lua_State *L) {
428444
struct skynet_context * ctx = lua_touserdata(L, lua_upvalueindex(1));
@@ -462,6 +478,7 @@ luaopen_socketdriver(lua_State *L) {
462478
{ "close", lclose },
463479
{ "listen", llisten },
464480
{ "send", lsend },
481+
{ "lsend", lsendlow },
465482
{ "bind", lbind },
466483
{ "start", lstart },
467484
{ NULL, NULL },

Diff for: lualib/socket.lua

+1
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ function socket.block(id)
264264
end
265265

266266
socket.write = assert(driver.send)
267+
socket.lwrite = assert(driver.lsend)
267268

268269
function socket.invalid(id)
269270
return socket_pool[id] == nil

Diff for: skynet-src/skynet_socket.c

+5
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ skynet_socket_send(struct skynet_context *ctx, int id, void *buffer, int sz) {
115115
return 0;
116116
}
117117

118+
void
119+
skynet_socket_send_lowpriority(struct skynet_context *ctx, int id, void *buffer, int sz) {
120+
socket_server_send_lowpriority(SOCKET_SERVER, id, buffer, sz);
121+
}
122+
118123
int
119124
skynet_socket_listen(struct skynet_context *ctx, const char *host, int port, int backlog) {
120125
uint32_t source = skynet_context_handle(ctx);

Diff for: skynet-src/skynet_socket.h

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ void skynet_socket_free();
2222
int skynet_socket_poll();
2323

2424
int skynet_socket_send(struct skynet_context *ctx, int id, void *buffer, int sz);
25+
void skynet_socket_send_lowpriority(struct skynet_context *ctx, int id, void *buffer, int sz);
2526
int skynet_socket_listen(struct skynet_context *ctx, const char *host, int port, int backlog);
2627
int skynet_socket_connect(struct skynet_context *ctx, const char *host, int port);
2728
int skynet_socket_block_connect(struct skynet_context *ctx, const char *host, int port);

0 commit comments

Comments
 (0)