资源简介
《Linux高性能服务器编程》高清pdf+附带源码
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define MAX_EVENT_NUMBER 1024
static int pipefd[2];
int setnonblocking( int fd )
{
int old_option = fcntl( fd F_GETFL );
int new_option = old_option | O_NONBLOCK;
fcntl( fd F_SETFL new_option );
return old_option;
}
void addfd( int epollfd int fd )
{
epoll_event event;
event.data.fd = fd;
event.events = EPOLLIN | EPOLLET;
epoll_ctl( epollfd EPOLL_CTL_ADD fd &event );
setnonblocking( fd );
}
void sig_handler( int sig )
{
int save_errno = errno;
int msg = sig;
send( pipefd[1] ( char* )&msg 1 0 );
errno = save_errno;
}
void addsig( int sig )
{
struct sigaction sa;
memset( &sa ‘\0‘ sizeof( sa ) );
sa.sa_handler = sig_handler;
sa.sa_flags |= SA_RESTART;
sigfillset( &sa.sa_mask );
assert( sigaction( sig &sa NULL ) != -1 );
}
int main( int argc char* argv[] )
{
if( argc <= 2 )
{
printf( “usage: %s ip_address port_number\n“ basename( argv[0] ) );
return 1;
}
const char* ip = argv[1];
int port = atoi( argv[2] );
int ret = 0;
struct sockaddr_in address;
bzero( &address sizeof( address ) );
address.sin_family = AF_INET;
inet_pton( AF_INET ip &address.sin_addr );
address.sin_port = htons( port );
int listenfd = socket( PF_INET SOCK_STREAM 0 );
assert( listenfd >= 0 );
//int nReuseAddr = 1;
//setsockopt( listenfd SOL_SOCKET SO_REUSEADDR &nReuseAddr sizeof( nReuseAddr ) );
ret = bind( listenfd ( struct sockaddr* )&address sizeof( address ) );
if( ret == -1 )
{
printf( “errno is %d\n“ errno );
return 1;
}
//assert( ret != -1 );
ret = listen( listenfd 5 );
assert( ret != -1 );
epoll_event events[ MAX_EVENT_NUMBER ];
int epollfd = epoll_create( 5 );
assert( epollfd != -1 );
addfd( epollfd listenfd );
ret = socketpair( PF_UNIX SOCK_STREAM 0 pipefd );
assert( ret != -1 );
setnonblocking( pipefd[1] );
addfd( epollfd pipefd[0] );
// add all the interesting signals here
addsig( SIGHUP );
addsig( SIGCHLD );
addsig( SIGTERM );
addsig( SIGINT );
bool stop_server = false;
while( !stop_server )
{
int number = epoll_wait( epollfd events MAX_EVENT_NUMBER -1 );
if ( ( number < 0 ) && ( errno != EINTR ) )
{
printf( “epoll failure\n“ );
break;
}
for ( int i = 0; i < number; i++ )
{
int sockfd = events[i].data.fd;
if( sockfd == listenfd )
{
struct sockaddr_in client_address;
socklen_t client_addrlength = sizeof( client_address );
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2018-04-27 15:42 Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\
文件 6148 2018-04-27 15:42 Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\.DS_Store
目录 0 2018-04-27 15:42 __MACOSX\
目录 0 2018-04-27 15:42 __MACOSX\Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\
文件 120 2018-04-27 15:42 __MACOSX\Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\._.DS_Store
目录 0 2018-04-27 15:42 Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\
文件 6148 2018-04-27 15:42 Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\.DS_Store
目录 0 2018-04-27 15:42 __MACOSX\Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\
文件 120 2018-04-27 15:42 __MACOSX\Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\._.DS_Store
目录 0 2013-03-04 20:21 Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\9\
文件 2100 2012-05-11 21:55 Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\9\9-6mytalk_client.cpp
目录 0 2018-04-27 15:42 __MACOSX\Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\9\
文件 212 2012-05-11 21:55 __MACOSX\Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\9\._9-6mytalk_client.cpp
文件 2736 2012-06-13 02:53 Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\9\9-5unblockconnect.cpp
文件 212 2012-06-13 02:53 __MACOSX\Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\9\._9-5unblockconnect.cpp
文件 4303 2013-03-04 20:18 Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\9\9-8multi_port.cpp.bak
文件 212 2013-03-04 20:18 __MACOSX\Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\9\._9-8multi_port.cpp.bak
文件 4400 2012-05-11 01:39 Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\9\9-3mtlt.cpp
文件 212 2012-05-11 01:39 __MACOSX\Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\9\._9-3mtlt.cpp
文件 4254 2013-03-04 20:21 Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\9\9-8multi_port.cpp
文件 212 2013-03-04 20:21 __MACOSX\Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\9\._9-8multi_port.cpp
文件 2515 2012-05-06 15:23 Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\9\9-1use_select.cpp
文件 212 2012-05-06 15:23 __MACOSX\Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\9\._9-1use_select.cpp
文件 5749 2012-05-12 01:50 Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\9\9-7mytalk_server.cpp
文件 212 2012-05-12 01:50 __MACOSX\Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\9\._9-7mytalk_server.cpp
文件 3899 2012-05-10 22:41 Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\9\9-4oneshot.cpp
文件 212 2012-05-10 22:41 __MACOSX\Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\9\._9-4oneshot.cpp
文件 212 2013-03-04 20:21 __MACOSX\Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\._9
目录 0 2013-01-18 19:15 Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\11\
文件 3657 2012-05-24 16:26 Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\11\11-2lst_timer.h
目录 0 2018-04-27 15:42 __MACOSX\Linux楂樻€ц兘鏈嶅姟鍣ㄧ紪绋嬫竻鏅癙DF+婧愮爜\LinuxServerCodes\11\
............此处省略143个文件信息
相关资源
- Certified Wireless Network Administrator Offic
- Linux shell脚本攻略.pdf
- torque 6.1.2
- 狂神docker笔记超详细.zip
- 北京科技大学自动化学院小学期多人
- Linux命令行与shell脚本编程大全第3版中
- RabbitMQ-linux安装包以及安装教程.rar
- virtio-win-1.1.16.iso
- RTL8822CE_WiFi_linux_v5.7.3_35403_COEX20190531
- Linux/Unix Sed与awk第二版(真正高清版)
- understanding linux network internals.pdf
- RTL8188EUS_linux_v5.3.9_28540.20180806.7z
- linux系统打包工具mondorescue
- Ubuntu Linux轻松入门(PPT)
- 只是为了好玩:Linux之父林纳斯自传
- redis-desktop-manager_0.9.2.19_amd64.deb for l
- SlickEdit Pro 2016 V21 WIN与LINUX x64 破解
- 基于linux的QT4精彩分析上
- 周立功《嵌入式Linux开发教程上册》
- RTL8188EUS_linux_v5.3.9_28540.20180806
- RTL8822CE_WiFi_linux_v5.7.3_34277_COEX20190531
- linux-xlnx-xilinx-v2018.3.tar.gz
- eclipse Kepler SR2 for Linux 64位 安装包 g
- fmxlinux1.46版
- gcc-linaro-6.3.1-2017.05-x86_64_aarch64-linux-
- p6880880_112000_Linux-x86-64.zip
- Linux运维之道
- OPatch_Linux-x86-64_11.2.0.3.21.7z
- Linux命令详解词典.pdf
- tor-browser-linux64-7.0.9_zh-CN.tar.xz
评论
共有 条评论