Use abstraction because Windows is not POSIX
Fixes #138 Change-Id: I4d9b49762e318fe91f1561ed315829b43daefef4
This commit is contained in:
parent
3624d5e5eb
commit
7eceac758c
|
@ -199,6 +199,17 @@ static inline int close_socket(int sock)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline void socket_block(int fd)
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
unsigned long nonblock = 0;
|
||||||
|
ioctlsocket(fd, FIONBIO, &nonblock);
|
||||||
|
#else
|
||||||
|
int oldopts = fcntl(fd, F_GETFL, 0);
|
||||||
|
fcntl(fd, F_SETFL, oldopts & ~O_NONBLOCK);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static inline void socket_nonblock(int fd)
|
static inline void socket_nonblock(int fd)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
|
@ -59,7 +59,7 @@ static int remote_bitbang_buf_full(void)
|
||||||
/* Read any incoming data, placing it into the buffer. */
|
/* Read any incoming data, placing it into the buffer. */
|
||||||
static void remote_bitbang_fill_buf(void)
|
static void remote_bitbang_fill_buf(void)
|
||||||
{
|
{
|
||||||
fcntl(remote_bitbang_fd, F_SETFL, O_NONBLOCK);
|
socket_nonblock(remote_bitbang_fd);
|
||||||
while (!remote_bitbang_buf_full()) {
|
while (!remote_bitbang_buf_full()) {
|
||||||
unsigned contiguous_available_space;
|
unsigned contiguous_available_space;
|
||||||
if (remote_bitbang_end >= remote_bitbang_start) {
|
if (remote_bitbang_end >= remote_bitbang_start) {
|
||||||
|
@ -148,7 +148,7 @@ static int remote_bitbang_rread(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Enable blocking access. */
|
/* Enable blocking access. */
|
||||||
fcntl(remote_bitbang_fd, F_SETFL, 0);
|
socket_block(remote_bitbang_fd);
|
||||||
char c;
|
char c;
|
||||||
ssize_t count = read(remote_bitbang_fd, &c, 1);
|
ssize_t count = read(remote_bitbang_fd, &c, 1);
|
||||||
if (count == 1) {
|
if (count == 1) {
|
||||||
|
|
Loading…
Reference in New Issue