📄 csocket.h
字号:
#ifndef __CSOCKET_H__
#define __CSOCKET_H__
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <netdb.h>
#include <fcntl.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string>
#include <iostream>
using namespace std;
typedef enum socket_type { SERVER_TYPE = 0, CLIENT_TYPE } s_type;
typedef enum socket_state{ CONN_ERROR = -1, CONN_OK = 0, CONN_WAIT = 1 } s_state;
class Sock_instance
{
public:
Sock_instance(string hostname, unsigned port, s_type type);
~Sock_instance();
bool Connect();
int fd();
s_state state();
bool Send(string msg);
int Receive();
void Close();
unsigned char* data() const;
int datalen() const;
string http_head() const;
private:
string _hostname;
unsigned _port;
int _fd;
s_state _state;
s_type _type;
unsigned char *_data;
int _datalen;
string _http_head;
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -