MCPcopy Create free account
hub / github.com/apache/httpd / lua_websocket_write

Function lua_websocket_write

modules/lua/lua_request.c:2407–2456  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2405
2406
2407static int lua_websocket_write(lua_State *L)
2408{
2409 const char *string;
2410 apr_status_t rv;
2411 size_t len;
2412 int raw = 0;
2413 char prelude;
2414 request_rec *r = ap_lua_check_request_rec(L, 1);
2415
2416 if (lua_isboolean(L, 3)) {
2417 raw = lua_toboolean(L, 3);
2418 }
2419 string = lua_tolstring(L, 2, &len);
2420
2421 if (raw != 1) {
2422 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(03013)
2423 "Websocket: Writing framed message to client");
2424
2425 prelude = 0x81; /* text frame, FIN */
2426 ap_rputc(prelude, r);
2427 if (len < 126) {
2428 ap_rputc(len, r);
2429 }
2430 else if (len < 65535) {
2431 apr_uint16_t slen = len;
2432 ap_rputc(126, r);
2433 slen = htons(slen);
2434 ap_rwrite((char*) &slen, 2, r);
2435 }
2436 else {
2437 apr_uint64_t llen = len;
2438 ap_rputc(127, r);
2439 llen = ap_ntoh64(&llen); /* ntoh doubles as hton */
2440 ap_rwrite((char*) &llen, 8, r);
2441 }
2442 }
2443 else {
2444 ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(03014)
2445 "Websocket: Writing raw message to client");
2446 }
2447 ap_rwrite(string, len, r);
2448 rv = ap_rflush(r);
2449 if (rv == APR_SUCCESS) {
2450 lua_pushboolean(L, 1);
2451 }
2452 else {
2453 lua_pushboolean(L, 0);
2454 }
2455 return 1;
2456}
2457
2458
2459static int lua_websocket_close(lua_State *L)

Callers

nothing calls this directly

Calls 5

ap_rputcFunction · 0.85
ap_rwriteFunction · 0.85
ap_ntoh64Function · 0.85
ap_rflushFunction · 0.85
ap_lua_check_request_recFunction · 0.70

Tested by

no test coverage detected