Commit 25477092 authored by Timothy B. Terriberry's avatar Timothy B. Terriberry Committed by Ralph Giles

Clean up winsock usage.

This keeps differences which can be cleanly abstracted away clean
 (closesocket, ioctlsocket, getsockopt, setsockopt), and makes
 differences which cannot be cleanly abstracted explicit (SOCKET,
 INVALID_SOCKET, WSAGetLastError/WSASetLastError).
It also gets rid of wsockwrapper.[ch], since it contained just a
 single function.

This can successfully pass the seeking_example tests on
 big.chained.blob over https when built with i686-w64-mingw32 and
 run under wine.
It does not solve the certificate distribution problems with using
 OpenSSL on a real Windows system.
parent d7591578
......@@ -17,7 +17,6 @@ libopusfile_la_LDFLAGS = -no-undefined \
-version-info @OP_LT_CURRENT@:@OP_LT_REVISION@:@OP_LT_AGE@
if OP_ENABLE_HTTP
if OP_WIN32
libopusfile_la_SOURCES += src/wsockwrapper.c
libopusfile_la_LIBADD += -lws2_32
endif
endif
......
This diff is collapsed.
#ifndef WINERRNO_H
#define WINERRNO_H
/********************************************************************
* *
* THIS FILE IS PART OF THE libopusfile SOFTWARE CODEC SOURCE CODE. *
* USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
* GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
* IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
* *
* THE libopusfile SOURCE CODE IS (C) COPYRIGHT 2012 *
* by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
* *
********************************************************************/
#if !defined(_opusfile_winerrno_h)
# define _opusfile_winerrno_h (1)
#include <errno.h>
# include <errno.h>
# include <winerror.h>
/* XXX: conflicts with MSVC errno definition */
#ifdef ENAMETOOLONG
#undef ENAMETOOLONG
#endif
#ifdef ENOTEMPTY
#undef ENOTEMPTY
#endif
/*These conflict with the MSVC errno definitions, but we don't need to use the
original ones in any file that deals with sockets.*/
# undef ENAMETOOLONG
# undef ENOTEMPTY
#define EWOULDBLOCK 35
#define EINPROGRESS 36
#define EALREADY 37
#define ENOTSOCK 38
#define EDESTADDRREQ 39
#define EMSGSIZE 40
#define EPROTOTYPE 41
#define ENOPROTOOPT 42
#define EPROTONOSUPPORT 43
#define ESOCKTNOSUPPORT 44
#define EOPNOTSUPP 45
#define EPFNOSUPPORT 46
#define EAFNOSUPPORT 47
#define EADDRINUSE 48
#define EADDRNOTAVAIL 49
#define ENETDOWN 50
#define ENETUNREACH 51
#define ENETRESET 52
#define ECONNABORTED 53
#define ECONNRESET 54
#define ENOBUFS 55
#define EISCONN 56
#define ENOTCONN 57
#define ESHUTDOWN 58
#define ETOOMANYREFS 59
#define ETIMEDOUT 60
#define ECONNREFUSED 61
#define ELOOP 62
#define ENAMETOOLONG 63
#define EHOSTDOWN 64
#define EHOSTUNREACH 65
#define ENOTEMPTY 66
#define EPROCLIM 67
#define EUSERS 68
#define EDQUOT 69
#define ESTALE 70
#define EREMOTE 71
# define EWOULDBLOCK (WSAEWOULDBLOCK-WSABASEERR)
# define EINPROGRESS (WSAEINPROGRESS-WSABASEERR)
# define EALREADY (WSAEALREADY-WSABASEERR)
# define ENOTSOCK (WSAENOTSOCK-WSABASEERR)
# define EDESTADDRREQ (WSAEDESTADDRREQ-WSABASEERR)
# define EMSGSIZE (WSAEMSGSIZE-WSABASEERR)
# define EPROTOTYPE (WSAEPROTOTYPE-WSABASEERR)
# define ENOPROTOOPT (WSAENOPROTOOPT-WSABASEERR)
# define EPROTONOSUPPORT (WSAEPROTONOSUPPORT-WSABASEERR)
# define ESOCKTNOSUPPORT (WSAESOCKTNOSUPPORT-WSABASEERR)
# define EOPNOTSUPP (WSAEOPNOTSUPP-WSABASEERR)
# define EPFNOSUPPORT (WSAEPFNOSUPPORT-WSABASEERR)
# define EAFNOSUPPORT (WSAEAFNOSUPPORT-WSABASEERR)
# define EADDRINUSE (WSAEADDRINUSE-WSABASEERR)
# define EADDRNOTAVAIL (WSAEADDRNOTAVAIL-WSABASEERR)
# define ENETDOWN (WSAENETDOWN-WSABASEERR)
# define ENETUNREACH (WSAENETUNREACH-WSABASEERR)
# define ENETRESET (WSAENETRESET-WSABASEERR)
# define ECONNABORTED (WSAECONNABORTED-WSABASEERR)
# define ECONNRESET (WSAECONNRESET-WSABASEERR)
# define ENOBUFS (WSAENOBUFS-WSABASEERR)
# define EISCONN (WSAEISCONN-WSABASEERR)
# define ENOTCONN (WSAENOTCONN-WSABASEERR)
# define ESHUTDOWN (WSAESHUTDOWN-WSABASEERR)
# define ETOOMANYREFS (WSAETOOMANYREFS-WSABASEERR)
# define ETIMEDOUT (WSAETIMEDOUT-WSABASEERR)
# define ECONNREFUSED (WSAECONNREFUSED-WSABASEERR)
# define ELOOP (WSAELOOP-WSABASEERR)
# define ENAMETOOLONG (WSAENAMETOOLONG-WSABASEERR)
# define EHOSTDOWN (WSAEHOSTDOWN-WSABASEERR)
# define EHOSTUNREACH (WSAEHOSTUNREACH-WSABASEERR)
# define ENOTEMPTY (WSAENOTEMPTY-WSABASEERR)
# define EPROCLIM (WSAEPROCLIM-WSABASEERR)
# define EUSERS (WSAEUSERS-WSABASEERR)
# define EDQUOT (WSAEDQUOT-WSABASEERR)
# define ESTALE (WSAESTALE-WSABASEERR)
# define EREMOTE (WSAEREMOTE-WSABASEERR)
#endif
#include <stdio.h>
#include "wsockwrapper.h"
int win32_poll(struct pollfd *fds, unsigned nfds, int timeout)
{
fd_set ifds, ofds, efds;
struct timeval tv;
unsigned i;
int rc;
FD_ZERO(&ifds);
FD_ZERO(&ofds);
FD_ZERO(&efds);
for (i = 0; i < nfds; ++i) {
fds[i].revents = 0;
if (fds[i].events & POLLIN)
FD_SET(fds[i].fd, &ifds);
if (fds[i].events & POLLOUT)
FD_SET(fds[i].fd, &ofds);
FD_SET(fds[i].fd, &efds);
}
if (timeout >= 0) {
tv.tv_sec = timeout / 1000;
tv.tv_usec = (timeout - tv.tv_sec * 1000) * 1000;
}
rc = select(255, &ifds, &ofds, &efds, timeout < 0 ? 0 : &tv);
if (rc > 0) {
for (i = 0; i < nfds; ++i) {
if (FD_ISSET(fds[i].fd, &ifds))
fds[i].revents |= POLLIN;
if (FD_ISSET(fds[i].fd, &ofds))
fds[i].revents |= POLLOUT;
if (FD_ISSET(fds[i].fd, &efds))
fds[i].revents |= POLLHUP;
}
}
return rc;
}
int win32_ftime(struct timeb *timer)
{
ftime(timer);
return 0;
}
#ifndef WSOCKWRAPPER_H
#define WSOCKWRAPPER_H
#include <winsock2.h>
#include <sys/timeb.h>
#define POLLIN 0x0001 /* There is data to read */
#define POLLPRI 0x0002 /* There is urgent data to read */
#define POLLOUT 0x0004 /* Writing now will not block */
#define POLLERR 0x0008 /* Error condition */
#define POLLHUP 0x0010 /* Hung up */
#define POLLNVAL 0x0020 /* Invalid request: fd not open */
struct pollfd {
SOCKET fd; /* file descriptor */
short events; /* requested events */
short revents; /* returned events */
};
#define poll(x, y, z) win32_poll(x, y, z)
int win32_poll(struct pollfd *, unsigned int, int);
int win32_ftime(struct timeb *timer);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment