#include <sock.h>
Public Methods | |
~Socket_basic () | |
Closes the socket, if this instance did open it itself. | |
Socket_basic (const Socket_basic &s) | |
Socket_basic (int desc=-1) | |
Construct an empty descriptor or copy a descriptor from a file decriptor. More... | |
void | Listen (const std::string &file_name) |
Open and create a socket UNIX socket and listen to it. More... | |
void | Connect (const std::string &file_name) |
Connect to a UNIX socket. More... | |
void | Accept (int server_sock) |
Get a connection via accepting it form a listening socket. More... | |
void | Close () |
Close the socket, if this instance did open it itself. | |
int | GetFD () |
Get the file descriptor and make the instance empty. More... | |
operator int () const | |
Get the file descriptor. More... | |
bool | IsOpen () const |
Check if the socket is connected/you are listening. |
This class can just "open" and close a UNIX socket or a connection to a UNIX socket. It abstracts all the unix specific stuff.
|
|
|
Construct an empty descriptor or copy a descriptor from a file decriptor. Usually you construct a empty object and open a socket with the Listen(const std::string&), Connect(const std::string&) or Accept(int). But if you have for some reason an open file descriptor, you can just attach it to this class. Indeed, you can not do anything with it in this class, since you will not open anything and Close() will not close it, since you opened, neither will ~Socket_basic(). But it provides an general interfase.
|
|
Open and create a socket UNIX socket and listen to it. Listening means, you waiting for client connections. If a clients connects, you may create a new instance of Socket_basic and accept it with a call like client_con.Accept(server_sock). Usually you need this only, if writing a server.
|
|
Connect to a UNIX socket. This is the method to connect to a server. If the server is accepting the connection, you are ready to communicate with write() and read().
|
|
Get a connection via accepting it form a listening socket. Use this to get an file descriptor to a incomming connection on a listening socket server_sock. You may create such a socket with the Listen(const std::string&) command.
|
|
Get the file descriptor and make the instance empty. In some rare cases (e.g. forking), you do not want, that the destruction of the instance closes the socket. This is when you will use this method. |
|
Get the file descriptor. You need the file descriptor for all basic i/o operation, e.g. read() or write(). |