⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 socket.h

📁 用c++包装好的线程库,直接拿来使用,提高效率.
💻 H
📖 第 1 页 / 共 2 页
字号:
      /** Get or set the size of the input buffer. */      s_rcvbuf    = SO_RCVBUF,      /** Get the communications style of the socket. */      s_type      = SO_TYPE,      /** Reset the error status of the socket */      s_error     = SO_ERROR    };  private:    int             _File_descriptor;    Mutex           _Read_lock, _Write_lock;    SocketAddress*  _Sin;    /**     * A Private method, to ensure that old values of mSin are     * freed prior to assigning a new value.     *     * @param s A new socket address value to assign.     */    void assign_Sin(SocketAddress *);  public:    /** Creates an empty socket, with no socket address applied to it. */    Socket();    /** The socket class is initialized around an already open socket. */    Socket(int);    /** The socket is a copy of another open socket. */    Socket(Socket&);    /**     * Create a socket, with the given address family, type and protocol.     *     * @param f The socket family.     * @param t The socket type, as in STREAM.     * @param p The protocol to use, as in TCP/UDP.     */    Socket(SocketAddress::t_afamily,__socket_type, int);    ~Socket();    /**     * Does the actual socket open, based on a given     * socked descriptor.     *     * @param des The socket descriptor to base the connection on.     */    void open(int);    /**     * Does the actual socket open, based on the family, type and protocol.     *     * @param fam The socket family.     * @param typ The socket type, such as STREAM.     * @param pro The socket protocol, such as TCP.     */    void open(SocketAddress::t_afamily,__socket_type,int);    /**     * Use this method, to close the socket.     */    void close();    /**     * Query weather this is a null socket, which is only connected     * with the void.     *     * @return true if the socket has no associated descriptor.     */    bool isNull();    /**     * Make a connection for the descriptor, if one has been     * created. @see open.     *     * @param host The string address of the peer to connect to.     * @param port The port, to connect with the peer on.     * @throws Exception::fatal if connect fails.     */    void connect(const char *,int);    /**     * Make a bind with a specific port, for the socket.  This will     * make the socket a server socket, and bind it to a specific     * port.     *     * @param port The port to bind to.     * @throws Exception::fatal if bind fails.     */    void bind(int);    /**     * Listen on a given port, specified above and allow a specific     * number of simultaneous listeners to be queued.     *     * @param list The listen count.     * @throws Exception::fatal if listen fails.     */    void listen(int);    /**     * Accept a connection on the descriptor, but only if this is a     * server socket.     *     * @return Pointer to a socket of a client, or 0 if no client.     * @throws Exception::fatal if socket family is unknown.     */    Socket* accept();    /**     * Send a message to the socket.     *     * This method wraps around the C function send, which takes a socket     * as its first parameter, and associates this method with the socket     * itself.  All other parameters are the same as with the C counterpart     * and it returns the same value.     *     * @param m Message to send.     * @param l length of message to send.     * @param f Flags.     * @return Length of data sent, or error.     */    int send(const char *,int,int);    /**     * Send a message through the socket.  This method is similar     * to the one above, except it takes a string as a parameter.     *     * @param s String to send.     * @param f Flags.     * @return Actual bytes sent.     */    int send(const std::string&,int);    /**     * Send a message to a given destination, via this socket.     *     * As with the send method, this method wraps around the C     * function sendto.  It associates this function with the socket     * that it takes as its first parameter.  all other parameters     * and return values remain the same.     *     * @param s Message to send.     * @param l Length of message to send.     * @param l Flags.     * @param d To address.     * @return Length of data sent, or error.     */    int sendTo(const char *,int,int,SocketAddress&);    /**     * This method differs from the one above, only that it takes     * a string as its parameter, that points to the data to send,     * rather than a character buffer.     *     * @param s String to send.     * @param f Flags.     * @param d Socket address of destination.     * @return Actual bytes sent.     */    int sendTo(const std::string&,int,SocketAddress&);    /**     * Send a message through this socket.     *     * @param m Message to send.     * @param f Flags.     */    int sendMsg(MessageHeader&,int);    /**     * Receive a message from a socket.     *     * @param s Buffer to put message in.     * @param l Length of buffer.     * @param f Flags.     * @return Length of data read.     */    int recv(void *,int,uint);    /**     * Receive a message from a socket.     *     * @param b Buffer for data.     * @param l Length of buffer.     * @param f Flags.     * @param s Socket to read from.     * @return Length of data read.     */    int recvFrom(void *,int,uint,SocketAddress&);    /**     * Receive a message from a socket, using the MessageHeader     * structure.     *     * @param m Message header.     * @param f Flags.     */    int recvMsg(MessageHeader&,int);    /**     * Read data from this socket.     *     * @param s Space to put the read bytes..     * @param l The number of available space in the buffer.     * @return Number of bytes actually read.     */    int read(const char *,int);    /**     * Write data to this socket.     *     * @param s Buffer containing data to write.     * @param l Number of bytes to write.     * @return Actual bytes written.     */    int write(const char *,int);    /**     * Write data to this socket.     *     * @param s Data string to write.     * @return Actual bytes written.     */    int write(const std::string&);    /**     * Obtain the name of the peer, this socket is connected     * with.     *     * @return socket address of the peer.     */    SocketAddress *peer();    /**     * Get the options associated with this socket. Keep in mind,     * that this routine takes one parameter, which can have     * different characteristics, depending on the option that     * is desired.     *     * @param o Socket option to query.     * @return the integer value requested.     */    int getOption(t_options);    /**     * Set some options, for the socket.  These options are     * defined in t_option.     *     * @param o The option to set.     * @param i The value to set it too.     * @return true if successfull.     */    bool setOption(t_options,int);    /**     * Specify what will happen, when the socket is of a type that     * promises reliable delivery and still has undelivered data, when     * it is closed.     * @param b Weather it will linger or not.     * @param t The timeout period.     * @return true if successful.     */     bool linger(bool,int);    /**     * This operator obtains the socket descriptor associated with     * this socket.     *     * @return socket descriptor.     */    operator int();    /**     * This operator obtains the socket addres associated with     * this socket.     *     * @return socket address used by this socket.     */    operator SocketAddress *();    Socket& operator =(Socket&);    bool    operator ==(Socket&);    /**     * This operator will verify weather the socket is open and     * functioning.     *     * @return true if the socket is ok.     */    operator bool();  protected:    void verifySocket();  };};#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -