MiniOB 1
MiniOB is one mini database, helping developers to learn how database works.
载入中...
搜索中...
未找到
Public 成员函数 | 静态 Public 成员函数 | Private 成员函数 | 静态 Private 成员函数 | Private 属性 | 静态 Private 属性 | 所有成员列表
Server类 参考

负责接收客户端消息并创建任务 更多...

#include <server.h>

Public 成员函数

 Server (ServerParam input_server_param)
 
int serve ()
 
void shutdown ()
 

静态 Public 成员函数

static void init ()
 
static void close_connection (Communicator *comm)
 

Private 成员函数

int set_non_block (int fd)
 将socket描述符设置为非阻塞模式 更多...
 
int start ()
 
int start_tcp_server ()
 启动TCP服务
 
int start_unix_socket_server ()
 启动Unix Socket服务 更多...
 
int start_stdin_server ()
 

静态 Private 成员函数

static void accept (int fd, short ev, void *arg)
 接收到新的连接时,调用此函数创建Communicator对象 更多...
 
static void recv (int fd, short ev, void *arg)
 接收到客户端消息时,调用此函数创建任务 更多...
 

Private 属性

volatile bool started_ = false
 
int server_socket_ = -1
 监听套接字,是一个描述符
 
struct event_base * event_base_ = nullptr
 libevent对象
 
struct event * listen_ev_ = nullptr
 libevent监听套接字事件
 
ServerParam server_param_
 服务启动参数
 
CommunicatorFactory communicator_factory_
 通过这个对象创建新的Communicator对象
 

静态 Private 属性

static common::Stage * session_stage_ = nullptr
 通过这个对象创建新的请求任务
 

详细描述

负责接收客户端消息并创建任务

当前支持网络连接,有TCP和Unix Socket两种方式。通过命令行参数来指定使用哪种方式。 启动后监听端口或unix socket,使用libevent来监听事件,当有新的连接到达时,创建一个Communicator对象进行处理。

成员函数说明

◆ accept()

void Server::accept ( int  fd,
short  ev,
void *  arg 
)
staticprivate

接收到新的连接时,调用此函数创建Communicator对象

此函数作为libevent中监听套接字对应的回调函数

参数
fdlibevent回调函数传入的参数,即监听套接字
ev本次触发的事件,通常是EV_READ
arg在注册libevent回调函数时,传入的参数,即Server对象

◆ recv()

void Server::recv ( int  fd,
short  ev,
void *  arg 
)
staticprivate

接收到客户端消息时,调用此函数创建任务

此函数作为libevent中客户端套接字对应的回调函数。当有新的消息到达时,调用此函数创建任务。

参数
fdlibevent回调函数传入的参数,即客户端套接字
ev本次触发的事件,通常是EV_READ
arg在注册libevent回调函数时,传入的参数,即Communicator对象

◆ set_non_block()

int Server::set_non_block ( int  fd)
private

将socket描述符设置为非阻塞模式

参数
fd指定的描述符

◆ start_stdin_server()

int Server::start_stdin_server ( )
private

在当前线程立即处理对应的事件

◆ start_unix_socket_server()

int Server::start_unix_socket_server ( )
private

启动Unix Socket服务

如果不删除源文件,可能会导致bind失败


该类的文档由以下文件生成: