Debian Codegraph @

src/compat/psock.cpp

raw symbols SCIP
1 /*
2 * Copyright (C) 1999 Philippe Dubois ([email protected])
3 * Copyright (C) 1999 Ross Combs ([email protected])
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */
19 #include "common/setup_before.h"
20 #ifdef WIN32
21
22 #include "psock.h"
23 #include "common/setup_after.h"
24
25
26 extern int psock_init(void)
27 {
28 WORD wVersionRequested;
29 WSADATA wsaData;
30
31 wVersionRequested = MAKEWORD(2, 2);
32
33 if (WSAStartup(wVersionRequested, &wsaData) != 0)
34 {
35 /* FIXME: Tell the user that we could not find a usable WinSock DLL. */
36 return -1;
37 }
38
39 return 0;
40 }
41
42 extern int psock_deinit(void)
43 {
44
45 if (WSACleanup() != 0)
46 {
47 return -1;
48 }
49
50 return 0;
51 }
52
53 extern int psock_ctl(int sd, int mode)
54 {
55 unsigned long nParam = 1; /* u_long or DWORD or what? */
56
57 return ioctlsocket(sd, mode, &nParam);
58 }
59
60 #else
61
62 #ifdef HAVE_UNISTD_H
63 # include <unistd.h>
64 #endif
65 #ifdef HAVE_FCNTL_H
66 # include <fcntl.h>
67 #else
68 # ifdef HAVE_SYS_FILE_H
69 # include <sys/file.h>
70 # endif
71 #endif
72 #include "psock.h"
73 #include "common/setup_after.h"
74
75
76 extern int psock_ctl(int sd, long int mode)
77 {
78 long int oldmode;
79
80 if ((oldmode = fcntl(sd, F_GETFL)) < 0)
81 oldmode = 0;
82 oldmode |= mode;
83 return fcntl(sd, F_SETFL, mode);
84 }
85
86 #endif