Try to write down your 1.1 million drops-
1. cross-platform development
1) header file inclusion
Use the define switch to include different libraries and define function types
# Ifndef Win32
# Include "socket_posix.h"
# Else/* Win32 */
# Include "socket_win32.h"
# Endif /*! Win32 */
The applicability of IF should be indicated at the end.
2) replace functions
# UNDEF errno
# Define errno wsagetlasterror ()
# Define read (FD, Buf, size) Recv (FD, Buf, size, 0)
2. Common macros
Today we see a very beautiful application:
Macro # is used to initialize IPv4 and IPv6 address information.
# Define fill_sockaddr (af_inet, sockaddr_in, sin, S, \ host, port, Count, addrlen, addrs) \ do \ {\ struct sockaddr_in * ADDR; \ int I; \ addrlen = sizeof (struct sockaddr_in); \ ADDR = (struct sockaddr_in *) calloc (count, addrlen); \ for (I = 0; I <count; ++ I) \ {\ ADDR [I]. sin ##_ family = af_inet; \ ADDR [I]. sin # _ Port = port; \ memcpy (& ADDR [I]. sin ##_ ADDR. s # _ ADDR, \ ADDR (host, I), host-> h_length); \}\\ addrs = (char *) ADDR ;\}\ while (0) # define fill_sockaddr (host, port, Count, addrlen, addrs) \ fill_sockaddr (af_inet, sockaddr_in, sin, S, \ host, port, Count, addrlen, addrs) # ifdef af_inet6 # define fill_sockaddr6 (host, port, Count, addrlen, addrs) \ fill_sockaddr (af_inet6, sockaddr_in6, sin6, S6, \ host, port, Count, addrlen, addrs) # endif/* af_inet6 */