Пример #1
0
static int
lshutdown(lua_State *L) {
    int id = luaL_checkinteger(L,1);
    struct skynet_context * ctx = lua_touserdata(L, lua_upvalueindex(1));
    skynet_socket_shutdown(ctx, id);
    return 0;
}
Пример #2
0
static void
command(struct skynet_context *ctx, struct package *P, int session, uint32_t source, const char *msg, size_t sz) {
	switch (msg[0]) {
	case 'R':
		// request a package
		if (P->closed) {
			skynet_send(ctx, 0, source, PTYPE_ERROR, session, NULL, 0);
			break;
		}
		if (!queue_empty(&P->response)) {
			assert(queue_empty(&P->request));
			struct response resp;
			queue_pop(&P->response, &resp);
			skynet_send(ctx, 0, source, PTYPE_RESPONSE | PTYPE_TAG_DONTCOPY, session, resp.msg, resp.sz);
		} else {
			struct request req;
			req.source = source;
			req.session = session;
			queue_push(&P->request, &req);
		}
		break;
	case 'K':
		// shutdown the connection
		skynet_socket_shutdown(ctx, P->fd);
		break;
	case 'I':
		report_info(ctx, P, session, source);
		break;
	default:
		// invalid command
		skynet_error(ctx, "Invalid command %.*s", (int)sz, msg);
		skynet_send(ctx, 0, source, PTYPE_ERROR, session, NULL, 0);
		break;
	};
}
Пример #3
0
// driver.shutdown(id)
// socket.shutdown(fd) 
// socket.lua
static int
lshutdown(lua_State *L) {
	int id = luaL_checkinteger(L,1);
	struct skynet_context * ctx = lua_touserdata(L, lua_upvalueindex(1));
	// skynet_socket_shutdown	skynet_socket
	// socket_server_shutdown	socket_server
	// send_request 'K'
	// close_socket 
	// force_close
	skynet_socket_shutdown(ctx, id);
	return 0;
}
Пример #4
0
static void
heartbeat(struct skynet_context *ctx, struct package *P) {
	if (P->recv == P->heartbeat) {
		if (!P->closed) {
			skynet_socket_shutdown(ctx, P->fd);
			skynet_error(ctx, "timeout %d", P->fd);
		}
	} else {
		P->heartbeat = P->recv = 0;
		skynet_command(ctx, "TIMEOUT", TIMEOUT);
	}
}