-
Notifications
You must be signed in to change notification settings - Fork 0
/
Packet.h
44 lines (40 loc) · 1.3 KB
/
Packet.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once
#include "Conf.h"
#include <sys/eventfd.h>
#include <sys/socket.h>
#include <cstring>
#include <cstdio>
#include <unistd.h>
#include <netinet/in.h>
#include <errno.h>
#include <sys/epoll.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string>
#include <netdb.h>
#define MAXLINE 4096
typedef struct sockaddr SA;
typedef struct epoll_event SE;
/*
* using thought in UNP
* encapsulate method
*/
int Accept(int sockfd,SA *cliaddr,socklen_t *addrlen);
int Socket(int family, int type, int protocol);
int Bind(int sockfd, SA* myaddr, socklen_t addrlen);
int Listen(int sockfd, int backlog);
int Fcntl(int fd, int cmd);
int Fcntl(int fd, int cmd, long arg);
int setnonblocking(int sockfd);
int Epoll_create(int size);
int Epoll_ctl(int epfd, int op, int fd, SE* event);
int Epoll_wait(int epfd, SE* events, int maxevents, int timeout);
ssize_t readn(int fd, std::string& inbuffer, bool& zero);
ssize_t writen(int fd, const void* vptr, size_t n);
int Open(const char* pathname, int oflags, mode_t mode);
int Close(int socket);
int Setsockopt(int sockfd, int level, int optname,
const void* optval, socklen_t* addrlenp);
int tcp_listen(const char* hostname, const char* service, socklen_t* addrlenp);
int Eventfd(unsigned int initval, int flags);