2012-04-21 21:13:50 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2014-01-01 00:50:59 +00:00
|
|
|
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
2015-01-07 16:46:50 +00:00
|
|
|
* Copyright (C) 2011-2015 - Daniel De Matteis
|
2012-01-24 20:00:30 +00:00
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
2012-01-24 20:00:30 +00:00
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
2012-04-21 21:13:50 +00:00
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
2012-01-24 20:00:30 +00:00
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
2012-04-21 21:31:57 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
2012-01-24 20:00:30 +00:00
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NETPLAY_COMPAT_H__
|
|
|
|
#define NETPLAY_COMPAT_H__
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2015-01-23 10:11:22 +00:00
|
|
|
#include <boolean.h>
|
2015-01-23 23:40:34 +00:00
|
|
|
#include <retro_inline.h>
|
2015-01-23 10:11:22 +00:00
|
|
|
|
2012-05-27 12:12:29 +00:00
|
|
|
#if defined(_WIN32) && !defined(_XBOX)
|
|
|
|
#ifndef _WIN32_WINNT
|
|
|
|
#define _WIN32_WINNT 0x0501
|
|
|
|
#endif
|
2015-01-24 00:06:53 +00:00
|
|
|
|
2012-05-27 12:12:29 +00:00
|
|
|
#define WIN32_LEAN_AND_MEAN
|
2015-01-24 00:06:53 +00:00
|
|
|
|
2012-05-27 12:12:29 +00:00
|
|
|
#include <winsock2.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#include <ws2tcpip.h>
|
2015-01-24 00:06:53 +00:00
|
|
|
|
2015-01-23 05:05:54 +00:00
|
|
|
#ifndef MSG_NOSIGNAL
|
|
|
|
#define MSG_NOSIGNAL 0
|
|
|
|
#endif
|
2015-01-24 00:06:53 +00:00
|
|
|
|
|
|
|
|
2012-05-27 12:12:29 +00:00
|
|
|
#elif defined(_XBOX)
|
2015-01-24 00:06:53 +00:00
|
|
|
|
2012-05-27 12:12:29 +00:00
|
|
|
#define NOD3D
|
|
|
|
#include <xtl.h>
|
2014-02-11 12:19:18 +00:00
|
|
|
#include <io.h>
|
2015-01-24 00:06:53 +00:00
|
|
|
|
2012-05-27 12:12:29 +00:00
|
|
|
#else
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
2015-01-24 00:06:53 +00:00
|
|
|
|
2012-09-16 02:04:25 +00:00
|
|
|
#ifndef __PSL1GHT__
|
2012-05-27 12:12:29 +00:00
|
|
|
#include <netinet/tcp.h>
|
2012-09-16 02:04:25 +00:00
|
|
|
#endif
|
2015-01-24 00:06:53 +00:00
|
|
|
|
2012-05-27 12:12:29 +00:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <netdb.h>
|
2012-05-27 12:18:37 +00:00
|
|
|
#include <fcntl.h>
|
2015-01-23 05:09:16 +00:00
|
|
|
#include <errno.h>
|
2012-05-27 12:12:29 +00:00
|
|
|
|
2012-09-16 02:04:25 +00:00
|
|
|
#if defined(__CELLOS_LV2__) && !defined(__PSL1GHT__)
|
2012-05-27 12:12:29 +00:00
|
|
|
#include <cell/sysmodule.h>
|
|
|
|
#include <netex/net.h>
|
2015-01-24 00:28:51 +00:00
|
|
|
|
|
|
|
#ifndef EWOULDBLOCK
|
|
|
|
#define EWOULDBLOCK SYS_NET_EWOULDBLOCK
|
|
|
|
#endif
|
|
|
|
|
2012-05-27 12:12:29 +00:00
|
|
|
#else
|
|
|
|
#include <signal.h>
|
|
|
|
#endif
|
2015-01-24 00:06:53 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static INLINE bool isagain(int bytes)
|
|
|
|
{
|
2015-01-24 00:10:44 +00:00
|
|
|
#if defined(_WIN32)
|
|
|
|
if (bytes != SOCKET_ERROR)
|
|
|
|
return false;
|
|
|
|
if (WSAGetLastError() != WSAEWOULDBLOCK)
|
|
|
|
return false;
|
|
|
|
return true;
|
2015-01-24 00:06:53 +00:00
|
|
|
#else
|
|
|
|
return (bytes < 0 && (errno == EAGAIN || errno == EWOULDBLOCK));
|
2012-05-27 12:12:29 +00:00
|
|
|
#endif
|
2015-01-24 00:06:53 +00:00
|
|
|
}
|
2012-05-27 12:12:29 +00:00
|
|
|
|
2012-01-24 23:02:59 +00:00
|
|
|
#ifdef _XBOX
|
|
|
|
#define socklen_t int
|
2014-12-23 20:21:49 +00:00
|
|
|
|
|
|
|
#ifndef h_addr
|
|
|
|
#define h_addr h_addr_list[0] /* for backward compatibility */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef SO_KEEPALIVE
|
|
|
|
#define SO_KEEPALIVE 0 /* verify if correct */
|
|
|
|
#endif
|
2012-01-24 23:02:59 +00:00
|
|
|
#endif
|
|
|
|
|
2015-01-23 05:36:58 +00:00
|
|
|
#ifndef MSG_NOSIGNAL
|
|
|
|
#define MSG_NOSIGNAL 0
|
|
|
|
#endif
|
|
|
|
|
2015-01-23 10:36:45 +00:00
|
|
|
#ifndef _WIN32
|
2012-01-24 20:00:30 +00:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2014-09-02 14:13:42 +00:00
|
|
|
/* Compatibility layer for legacy or incomplete BSD socket implementations.
|
|
|
|
* Only for IPv4. Mostly useful for the consoles which do not support
|
|
|
|
* anything reasonably modern on the socket API side of things. */
|
2012-01-24 20:00:30 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_SOCKET_LEGACY
|
|
|
|
|
|
|
|
#define sockaddr_storage sockaddr_in
|
2012-04-21 21:25:32 +00:00
|
|
|
#define addrinfo addrinfo_rarch__
|
2012-01-24 20:00:30 +00:00
|
|
|
|
|
|
|
struct addrinfo
|
|
|
|
{
|
|
|
|
int ai_flags;
|
|
|
|
int ai_family;
|
|
|
|
int ai_socktype;
|
|
|
|
int ai_protocol;
|
|
|
|
size_t ai_addrlen;
|
|
|
|
struct sockaddr *ai_addr;
|
|
|
|
char *ai_canonname;
|
|
|
|
struct addrinfo *ai_next;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef AI_PASSIVE
|
|
|
|
#define AI_PASSIVE 1
|
|
|
|
#endif
|
|
|
|
|
2014-09-02 14:13:42 +00:00
|
|
|
/* gai_strerror() not used, so we skip that. */
|
2012-01-24 20:00:30 +00:00
|
|
|
|
|
|
|
#endif
|
2015-01-23 05:29:36 +00:00
|
|
|
|
|
|
|
int getaddrinfo_rarch(const char *node, const char *service,
|
|
|
|
const struct addrinfo *hints,
|
|
|
|
struct addrinfo **res);
|
|
|
|
|
|
|
|
void freeaddrinfo_rarch(struct addrinfo *res);
|
2015-01-23 10:11:22 +00:00
|
|
|
|
|
|
|
bool socket_nonblock(int fd);
|
|
|
|
|
2015-01-23 10:36:45 +00:00
|
|
|
int socket_close(int fd);
|
|
|
|
|
2015-01-23 10:44:13 +00:00
|
|
|
int socket_select(int nfds, fd_set *readfs, fd_set *writefds,
|
|
|
|
fd_set *errorfds, struct timeval *timeout);
|
|
|
|
|
2015-01-23 18:43:40 +00:00
|
|
|
int socket_send_all_blocking(int fd, const void *data_, size_t size);
|
|
|
|
|
|
|
|
int socket_receive_all_blocking(int fd, void *data_, size_t size);
|
|
|
|
|
2015-01-28 07:55:02 +00:00
|
|
|
/**
|
|
|
|
* network_init:
|
|
|
|
*
|
|
|
|
* Platform specific socket library initialization.
|
|
|
|
*
|
|
|
|
* Returns: true (1) if successful, otherwise false (0).
|
|
|
|
**/
|
|
|
|
bool network_init(void);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* network_deinit:
|
|
|
|
*
|
|
|
|
* Deinitialize platform specific socket libraries.
|
|
|
|
**/
|
|
|
|
void network_deinit(void);
|
|
|
|
|
2012-01-24 20:00:30 +00:00
|
|
|
#endif
|
|
|
|
|