File: nonblock.h

package info (click to toggle)
libopenobex 1.7.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 972 kB
  • ctags: 1,552
  • sloc: ansic: 9,988; xml: 407; makefile: 96
file content (43 lines) | stat: -rw-r--r-- 1,189 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
	\file nonblock.h
	wrapper functions to enable/disable non-blocking
	OpenOBEX library - Free implementation of the Object Exchange protocol.

	Copyright (c) 2010 Hendrik Sattler, All Rights Reserved.

	OpenOBEX is free software; you can redistribute it and/or modify
	it under the terms of the GNU Lesser General Public License as
	published by the Free Software Foundation; either version 2.1 of
	the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU Lesser General Public License for more details.

	You should have received a copy of the GNU Lesser General Public
	License along with OpenOBEX. If not, see <http://www.gnu.org/>.
 */

#if defined(_WIN32)
#include <winsock2.h>
#else
#include <fcntl.h>
#endif

static __inline void socket_set_nonblocking(socket_t fd)
{
#if defined(_WIN32)
	unsigned long val = 1;

	(void)ioctlsocket(fd, FIONBIO, &val);

#else
	long status = fcntl(fd, F_GETFL);

	if (status == -1)
		status = 0;

	(void)fcntl(fd, F_SETFL, status | O_NONBLOCK);
#endif
}