]> git.donarmstrong.com Git - bamtools.git/blob - src/api/internal/io/NetWin_p.h
Fixed: premature EOF issues & updated Windows implementation
[bamtools.git] / src / api / internal / io / NetWin_p.h
1 // ***************************************************************************
2 // NetWin_p.h (c) 2011 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 8 December 2011 (DB)
6 // ---------------------------------------------------------------------------
7 // Provides common networking-related includes, etc. for Windows systems
8 //
9 // Note: requires Windows XP or later
10 // ***************************************************************************
11
12 #ifndef NETWIN_P_H
13 #define NETWIN_P_H
14
15 //  -------------
16 //  W A R N I N G
17 //  -------------
18 //
19 // This file is not part of the BamTools API.  It exists purely as an
20 // implementation detail. This header file may change from version to version
21 // without notice, or even be removed.
22 //
23 // We mean it.
24
25 #ifdef _WIN32 // <-- source files only include the proper Net*_p.h, but this is a double-check
26
27 #include <winsock2.h>  // <-- should bring 'windows.h' along with it
28 #include <Ws2tcpip.h>
29
30 #ifndef   BT_SOCKLEN_T
31 #  define BT_SOCKLEN_T int
32 #endif
33
34 #ifdef _MSC_VER
35 #  pragma comment(lib, "ws2_32.lib")
36 #endif
37
38 namespace BamTools {
39 namespace Internal {
40
41 // use RAII to ensure WSA is initialized
42 class WindowsSockInit {
43     public:
44         WindowsSockInit(void) {
45             WSAData wsadata;
46             WSAStartup(MAKEWORD(2,2), &wsadata); // catch error ?
47         }
48
49         ~WindowsSockInit(void) {
50             WSACleanup();
51         }
52 };
53
54 } // namespace Internal
55 } // namespace BamTools
56
57 #endif // _WIN32
58
59 #endif // NETWIN_P_H
60