Five Pitfalls of Linux Sockets Programming (developerWorks)
Posted Sep 21, 2005 15:04 UTC (Wed) by
ratz (guest, #32588)
Parent article:
Five Pitfalls of Linux Sockets Programming (developerWorks)
Generally:
These are very basic things one has to know when doing network
programming in general. Doing system programming and not handling every
return invariant is simply an assured way of giving you long debugging
nights. Read the man pages on how to handle errors or use a library if
you're not too seasoned a programmer. This is actually what I would
recommend to junior network programmers: use a library if you are serious
about writing a networking application.
Unless you are writing applications for fun there is the very important
aspect of performance which contains its own spectre of subtle pitfalls.
I mean not being able to solve an EADDRINUSE clearly shows that the
programmer did not even know of socket(7) and should thus maybe try to
write his application using one of the "dozens" of networking libraries
floating the network. Then of course there is the "pitfall" of not
knowing the appropriate system calls when it comes to performance:
facilities like epoll(4), sendfile(2) or others.
Documentation:
It's almost imperative to have the full Stevens' series books ready when
doing any serious socket programming. At least TCP Illustrated, Vol I and
III. A series of books not often referred to but in my opinion pretty
good are the "Internetworking with TCP/IP series by Douglas E. Comer &
David L. Stevens" Then of course it's very important to know the
appropriate man pages because (unfortunately) socket programming under
Linux can heavily diverge from other OS' socket programming and the
article's focus was Linux sockets programming. socket(7), ip(7) and the
reference man pages in those pages should be consulted.
Debugging:
Regarding tools for debugging your session, _please_ for heaven's sake do
not use the much depreciated (granted, only in the Linux world) tools
like: ifconfig, route and netstat. Please acquaint yourself with the
iproute2 architecture and its tools meanwhile provided by almost every
Linux distribution, such as:
1. ip (as a superset of ifconfig and route)
2. ss (as the socket information tool)
The other tools are not working correctly (race conditions because of
reading proc-fs instead of using netlink) and do not display the correct
information (ifconfig still tells its users that a secondary IP is an
interface for example).
(
Log in to post comments)