View Single Post
  #6 (permalink)  
Old August 10th, 2002
Moak
Guest
 
Posts: n/a
Post Development: socket redesign

Hi Max,

mainly about DNS and asynchronous socket class.... some ideas for a CAsyncSocket redesign:

- Okay we work usually IP based (just to get a starting point)
- Run a second thread which will resolve all pending DNS resolutions and store them in an array, big enough to cache all needed hostnames of an application. Size of this internal lookup table can be adjusted by user.
- Two new methods BOOL Resolve(unsigned long *ipaddr) and BOOL Resolve(char* hostname). Which will query the array (multithreading safe) and eighter return the result... or FALSE and error result ADDRESS_NOT_AVAILABLE (can't be resolved) or ADDRESS_RESOLVING. In any case, the methods return immadiately and do not block!
- User can query again and again for an address, until the address is resolved (in case of a FALSE return he has to continue to work with IP).
- New virtual override OnResolve() which will notify the socket when a name server lookup was finished. This event might be a sucessfull finished lookup or telling that address can't be resolved. OnResolve() will called once after a succesfull/unsucessfull lookup... or more technically whenever a Resolve() call will change the internal lookup table.

Other stuff:

- new virtual override OnReceiveLine(), which will only called when a full line was received. Simply override OnReceive with a call to ReceiveLine(), it will do line buffering in a per socket based buffer.
- add a status to each socket which can be queried with int GetStatus(), here what I use currently:

enum {
SOCKET_DEAD = 0, //socket is dead (delete socket)
SOCKET_DISCONNECTING, //socket is performing disconnect
SOCKET_UNCONNECTED, //socket is not connected
SOCKET_CONNECTING, //socket is connecting
SOCKET_CONNECTED, //socket is connected
SOCKET_LISTENING, //socket is listening (not available for incoming "client" sockets)
}
;

Some things simplyfied (e.g. method parameters and return values). I have a small testing code which is only a few lines... don't ask me for full code before end of summer.

Greets, Moak

PS: Raphael, of course you would do better.
Reply With Quote