Sockets Library Design (include placement, etc)

Jul 16, 2010 at 7:52pm
Hello, so I'm working on another personal project and I want to write an improved sockets library for myself.

I currently have a basic Socket class written in a Socket.h and the implementation in Socket.cpp. It is contained within the namespace "Sockets". I'm going to write a derived TCPSocket class next inside of it's own files.

Sockets.h includes WinSock2.h. Is it common to place these types of header files in multiple files? TCPSocket uses functions, macros, etc from WinSock2.h as well.

Should TCPSocket.h just include Socket.h since Socket.h already has WinSock.h included? This has really stumped me and any design decision help would be much appreciated.

Thanks,
Mack
Last edited on Jul 16, 2010 at 7:53pm
Jul 17, 2010 at 2:47pm
I'm thinking TCPSocket should just include Socket.h since it is derived, but I'm not 100%.
Jul 19, 2010 at 1:01pm
Yes, just include Socket.h, since Socket.h also includes Winsock.h / Winsock2.h you dont need to include it again.
Jul 19, 2010 at 3:57pm
I, personally, include the header in any file that uses one of its symbols.
Jul 19, 2010 at 4:21pm
Try to avoid including winsock2.h in any header files at all and include it only in the cpp files.
It's bad practice to inject huge header trees into a project when it can be avoided (fairly easy for a socket class). It increases compilation times and in the case of the Windows headers, they add a whole bunch of nasty defines..
Personally, I wouldn't use a library that injects the Windows headers into my units (partly because it would break some of my projects due to said defines), if that counts for anything.
Last edited on Jul 19, 2010 at 4:28pm
Topic archived. No new replies allowed.