📄 socket.h
字号:
/************************************************************************* * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * *************************************************************************/#ifndef _SOCKET_H__#define _SOCKET_H__#include "global.h"#include "exception.h"#include "logger.h"#include "i18n.h"#include <unistd.h>#include <arpa/inet.h>#include <netdb.h>#include <sys/socket.h>#include <sys/time.h>#include <netinet/in.h>#include <errno.h>#include <string>using namespace std;/** * This class describes a socket. * This class is intended to be a base class for more specific * socket implementations, eg. tcp sockets or unix domain * sockets. Consequently it is a virtual class that cannot * be instantiated. * * @author Timo Benk <t_benk@web.de> */class Socket : public Logger{ public: /** * Constructor. * * @param host The host this socket is connected to. */ Socket (const string &host); /** * Constructor. * * @param host The host this socket is connected to. * @param fd The file descriptor this socket uses for IO. */ Socket (const string &host, int fd); /** * Destructor. */ virtual ~Socket (); protected: /** * The host that we want to connect to. */ string host; /** * The socket file descriptor this socket uses for IO. */ int sockfd; public: /** * Connect this socket. */ virtual void connect () = 0; /** * Returns the name of the localhost or the * string "localhost" if something goes wrong. * * @returns The name of the localhost or localhost. */ string localhost (); /** * Reads one line from the socket. * * @returns One line read from the socket. * * @throws TransferException * On any uncommon event that occurs while receiving * the data. */ string readSocket (); /** * Writes data to the socket. * * @param data The data string that should be written to * the socket. * * @throws TransferException * On any uncommon event that occurs while sending * the data. */ void writeSocket (const string &data);};#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -