-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create common API for sockets #1
Comments
in which particular document here we should write API stuff? |
EasySocket has to work equally on supported platforms. It should provide interface for work with TCP/UDP protocols, as well as for IPv4, IPv6 Easy interface for connection to host probably it would be great to implement methods for Easy access to the state of socket. |
bool connectToHost(const string hostName, int port, OpenMode openMode, NetworkProtocol protocol, int &error); method connectToHost attempts to make a connection to hostName on the given port. The protocol parameter can be used to specify which network protocol to use (IPv4 or IPv6). enum NetworkProtocol { IPv4Protocol, IPv6Protocol, AnyIPProtocol... }
enum OpenMode { NotOpen, ReadOnly, WriteOnly, ReadWrite...} hostName may be an IP address in string form ("10.0.0.1"), or it may be a host name ("easysock.com"). Port is in native byte order. bool connectToHost(const string hostName, int port, OpenMode openMode = ReadWrite, int &error) This is an overloaded function and attempts to make a connection to address on port port. void disconnectFromHost() Attempts to close the socket. As I know If there is pending data waiting to be written, socket will enter in sort of "closing state" and wait until all data has been written. Eventually, it will switch to unconnected state. void close() Close the current connection of socket. And assumably discarding any pending data in the write buffer. bool isValid() const Returns true if the socket is valid and ready for use otherwise returns false. in implementation: if we pass socket to any one of the windows socket functions (for example getsockopt()), if the socket is invalid, it will return SOCKET_ERROR while WSAGetLastError() will return WSAENOTSOCK. It is important to note that INVALID_SOCKET does not equal 0. to be continued... |
Also we need to create a unified cross-platform classification of errors, 'cos it's not similar for different os's SocketError error() const Returns the type of error that last occurred. I would suggest creating firstly a set of general codes:
|
SocketState state() const return state of socket: enum SocketState
|
Some function in my branch i added but we clearly must separate common functions, client and server ones. |
The main task is to create common socket data : socket number (some OS descriptor), socket network address (ip 4/6, and port for server). |
Posiibly as you written before could be some socket state as int (which is mapping for WinSocks to enum that you have posted previously). |
We should review our demands and after that we could understand how API should look.
Basically, we must have common C API and 3 C implementations (Linux, Unix, Windows). Implementations that including conditionally on what OS is selected (Have not understood all details completely). Also I think there should be C++ wrapping (03 and 11) for C++ programs.
Library must be lightweight as possible (without any synch primitives, threads and so on).
The text was updated successfully, but these errors were encountered: