csocket.h

来自「一个简单的http下载程序,用C++在linux下写了一个简单的http下载程序」· C头文件 代码 · 共 52 行

H
52
字号
#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 + =
减小字号Ctrl + -
显示快捷键?