当前位置: 技术问答>linux和unix
linux下服务器编程问题
来源: 互联网 发布时间:2016-11-18
本文导语: /* * 服务器端的源代码 */ #include #include #include #include #include #include #include using namespace std; #define MAXFDS 256 #define EVENTS 100 #define PORT 8888 int epfd; bool setNonBlock(int fd) { int flags = fcntl(fd, F_GETFL, 0); flag...
/*
* 服务器端的源代码
*/
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define MAXFDS 256
#define EVENTS 100
#define PORT 8888
int epfd;
bool setNonBlock(int fd)
{
int flags = fcntl(fd, F_GETFL, 0);
flags |= O_NONBLOCK;
if(-1 == fcntl(fd, F_SETFL, flags))
return false;
return true;
}
int main(int argc, char* argv[], char* evp[])
{
int fd, nfds;
int on = 1;
char* buffer[512];
struct sockaddr_in saddr;
socklen_t caddr;
struct epoll_event ev, events[EVENTS];
if(-1 == socket(AF_INET, SOCK_STREAM, 0))
{
std::cout
* 服务器端的源代码
*/
#include
#include
#include
#include
#include
#include
#include
using namespace std;
#define MAXFDS 256
#define EVENTS 100
#define PORT 8888
int epfd;
bool setNonBlock(int fd)
{
int flags = fcntl(fd, F_GETFL, 0);
flags |= O_NONBLOCK;
if(-1 == fcntl(fd, F_SETFL, flags))
return false;
return true;
}
int main(int argc, char* argv[], char* evp[])
{
int fd, nfds;
int on = 1;
char* buffer[512];
struct sockaddr_in saddr;
socklen_t caddr;
struct epoll_event ev, events[EVENTS];
if(-1 == socket(AF_INET, SOCK_STREAM, 0))
{
std::cout