Five risks in Linux socket programming-general Linux technology-Linux programming and kernel information. The following is a detailed description. Socket API is a standard API used in network application development. Although this API is simple, developers may experience some common problems. This article identifies some of the most common risks and shows you how to avoid them.
On the 4.2 BSD UNIX®For the first time introduced in the operating system, Sockets API is now a standard feature of any operating system. In fact, it is difficult to find a modern language that does not support Sockets APIs. This API is quite simple, but new developers still encounter some common risks.
This article identifies the risks and shows you how to avoid them.
Hazard 1. Ignore returned status
The first hidden danger is obvious, but it is the easiest mistake for new developers. If you ignore the return status of the function, you may be lost when they fail or are partially successful. In turn, this may spread errors, making it difficult to locate the source of the problem.
Capture and check each returned status, rather than ignoring them. Consider the example shown in Listing 1, a socket send function.
Listing 1. Ignore the status returned by the API Function