kopia lustrzana https://gitlab.com/sane-project/backends
Updates to use sockets on mingw
Add missing WSAStartup() and WSACleanup() code required on windows to use ws2_32 library. Also, O_NONBLOCK is tricky even on other platforms so create a function to set that so portability logic doesn't need to be done in every backend. Windows requires using a non standard function to enable nonblocking mode and also doesn't support querying current state.merge-requests/1/head
rodzic
0a6d41ff59
commit
1aa332d710
|
@ -31,6 +31,7 @@
|
|||
extern SANE_Status sanei_udp_open(const char *host, int port, int *fdp);
|
||||
extern SANE_Status sanei_udp_open_broadcast(int *fdp);
|
||||
extern void sanei_udp_close(int fd);
|
||||
extern void sanei_udp_set_nonblock(int fd, SANE_Bool nonblock);
|
||||
extern ssize_t sanei_udp_write(int fd, const u_char * buf, int count);
|
||||
extern ssize_t sanei_udp_read(int fd, u_char * buf, int count);
|
||||
extern ssize_t sanei_udp_write_broadcast(int fd, int port, const u_char * buf, int count);
|
||||
|
|
|
@ -65,10 +65,19 @@ sanei_tcp_open(const char *host, int port, int *fdp)
|
|||
int fd, err;
|
||||
struct sockaddr_in saddr;
|
||||
struct hostent *h;
|
||||
#ifdef HAVE_WINSOCK2_H
|
||||
WSADATA wsaData;
|
||||
#endif
|
||||
|
||||
DBG_INIT();
|
||||
DBG(1, "%s: host = %s, port = %d\n", __FUNCTION__, host, port);
|
||||
|
||||
#ifdef HAVE_WINSOCK2_H
|
||||
err = WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||
if (err != 0)
|
||||
return SANE_STATUS_INVAL;
|
||||
#endif
|
||||
|
||||
h = gethostbyname(host);
|
||||
|
||||
if (h == NULL || h->h_addr_list[0] == NULL
|
||||
|
@ -100,6 +109,9 @@ void
|
|||
sanei_tcp_close(int fd)
|
||||
{
|
||||
close(fd);
|
||||
#ifdef HAVE_WINSOCK2_H
|
||||
WSACleanup();
|
||||
#endif
|
||||
}
|
||||
|
||||
ssize_t
|
||||
|
|
|
@ -115,10 +115,19 @@ SANE_Status
|
|||
sanei_udp_open(const char *host, int port, int *fdp)
|
||||
{
|
||||
int status;
|
||||
#ifdef HAVE_WINSOCK2_H
|
||||
WSADATA wsaData;
|
||||
#endif
|
||||
|
||||
DBG_INIT();
|
||||
DBG(1, "%s\n", __func__);
|
||||
|
||||
#ifdef HAVE_WINSOCK2_H
|
||||
status = WSAStartup(MAKEWORD(2, 2), &wsaData);
|
||||
if (status != 0)
|
||||
return SANE_STATUS_INVAL;
|
||||
#endif
|
||||
|
||||
status = sanei_udp_socket(fdp, 0);
|
||||
if (status != SANE_STATUS_GOOD)
|
||||
return status;
|
||||
|
@ -151,6 +160,9 @@ void
|
|||
sanei_udp_close(int fd)
|
||||
{
|
||||
close(fd);
|
||||
#ifdef HAVE_WINSOCK2_H
|
||||
WSACleanup();
|
||||
#endif
|
||||
}
|
||||
|
||||
ssize_t
|
||||
|
@ -174,6 +186,25 @@ sanei_udp_write_broadcast(int fd, int port, const u_char * buf, int count)
|
|||
(struct sockaddr *)&saddr, sizeof(saddr));
|
||||
}
|
||||
|
||||
void
|
||||
sanei_udp_set_nonblock(int fd, SANE_Bool nonblock)
|
||||
{
|
||||
#ifdef HAVE_WINSOCK2_H
|
||||
u_long mode=nonblock;
|
||||
|
||||
ioctlsocket(fd, FIONBIO, &mode);
|
||||
#else
|
||||
long flags;
|
||||
|
||||
save_flags = flags = fcntl(fd, F_GETFL, 0L);
|
||||
if (nonblock)
|
||||
flags |= O_NONBLOCK;
|
||||
else
|
||||
flags &= ~O_NONBLOCK;
|
||||
fcntl(fd, F_SETFL, flags);
|
||||
#endif
|
||||
}
|
||||
|
||||
ssize_t
|
||||
sanei_udp_read(int fd, u_char * buf, int count)
|
||||
{
|
||||
|
|
Ładowanie…
Reference in New Issue