project_files/frontlib/socket.c
author Medo <smaxein@googlemail.com>
Thu, 07 Jun 2012 02:45:18 +0200
changeset 7175 038e3415100a
parent 7171 906e72caea7b
child 7177 bf6cf4dd847a
permissions -rw-r--r--
Added ini reading/writing for game schemes to the frontend lib
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7171
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
     1
#include "socket.h"
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
     2
#include "logging.h"
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
     3
#include <stdlib.h>
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
     4
#include <SDL_net.h>
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
     5
#include <time.h>
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
     6
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
     7
typedef struct _flib_tcpsocket {
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
     8
	TCPsocket sock;
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
     9
	SDLNet_SocketSet sockset;
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    10
} _flib_tcpsocket;
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    11
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    12
typedef struct _flib_acceptor {
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    13
	TCPsocket sock;
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    14
	uint16_t port;
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    15
} _flib_acceptor;
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    16
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    17
static uint32_t get_peer_ip(TCPsocket sock) {
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    18
	IPaddress *addr = SDLNet_TCP_GetPeerAddress(sock);
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    19
	return SDLNet_Read32(&addr->host);
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    20
}
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    21
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    22
static bool connection_is_local(TCPsocket sock) {
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    23
	return get_peer_ip(sock) == (uint32_t)((127UL<<24)+1); // 127.0.0.1
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    24
}
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    25
7175
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    26
static flib_tcpsocket flib_socket_create(TCPsocket sdlsock) {
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    27
	flib_tcpsocket result = malloc(sizeof(_flib_tcpsocket));
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    28
	if(!result) {
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    29
		flib_log_e("Can't allocate socket: Out of memory!");
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    30
		return NULL;
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    31
	}
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    32
	result->sock = sdlsock;
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    33
	result->sockset = SDLNet_AllocSocketSet(1);
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    34
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    35
	if(!result->sockset) {
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    36
		flib_log_e("Can't allocate socket: Out of memory!");
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    37
		SDLNet_FreeSocketSet(result->sockset);
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    38
		free(result);
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    39
		return NULL;
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    40
	}
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    41
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    42
	SDLNet_AddSocket(result->sockset, (SDLNet_GenericSocket)result->sock);
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    43
	return result;
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    44
}
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    45
7171
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    46
flib_acceptor flib_acceptor_create(uint16_t port) {
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    47
	flib_acceptor result = malloc(sizeof(_flib_acceptor));
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    48
	if(!result) {
7175
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    49
		flib_log_e("Can't allocate acceptor: Out of memory!");
7171
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    50
		return NULL;
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    51
	}
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    52
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    53
	IPaddress addr;
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    54
	addr.host = INADDR_ANY;
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    55
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    56
	if(port > 0) {
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    57
		result->port = port;
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    58
		SDLNet_Write16(port, &addr.port);
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    59
		result->sock = SDLNet_TCP_Open(&addr);
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    60
		if(result->sock) {
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    61
			return result;
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    62
		} else {
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    63
			flib_log_e("Unable to listen on port %u: %s", port, SDLNet_GetError());
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    64
			free(result);
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    65
			return NULL;
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    66
		}
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    67
	} else {
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    68
		/* SDL_net does not seem to have a way to listen on a random unused port
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    69
		   and find out which port that is, so let's try to find one ourselves. */
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    70
		srand(time(NULL));
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    71
		rand();
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    72
		for(int i=0; i<1000; i++) {
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    73
			// IANA suggests using ports in the range 49152-65535 for things like this
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    74
			result->port = 49152+(rand()%(65535-49152));
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    75
			SDLNet_Write16(result->port, &addr.port);
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    76
			result->sock = SDLNet_TCP_Open(&addr);
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    77
			if(result->sock) {
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    78
				return result;
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    79
			} else {
7175
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    80
				flib_log_w("Unable to listen on port %u: %s", result->port, SDLNet_GetError());
7171
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    81
			}
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    82
		}
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    83
		flib_log_e("Unable to listen on a random unused port.");
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    84
		free(result);
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    85
		return NULL;
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    86
	}
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    87
}
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    88
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    89
uint16_t flib_acceptor_listenport(flib_acceptor acceptor) {
7175
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    90
	if(!acceptor) {
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    91
		flib_log_e("Call to flib_acceptor_listenport with acceptor==null");
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    92
		return 0;
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    93
	}
7171
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    94
	return acceptor->port;
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    95
}
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    96
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
    97
void flib_acceptor_close(flib_acceptor *acceptorptr) {
7175
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    98
	if(!acceptorptr) {
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
    99
		flib_log_e("Call to flib_acceptor_close with acceptorptr==null");
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   100
	} else if(*acceptorptr) {
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   101
		SDLNet_TCP_Close((*acceptorptr)->sock);
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   102
		free(*acceptorptr);
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   103
		*acceptorptr = NULL;
7171
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   104
	}
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   105
}
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   106
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   107
flib_tcpsocket flib_socket_accept(flib_acceptor acceptor, bool localOnly) {
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   108
	if(!acceptor) {
7175
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   109
		flib_log_e("Call to flib_socket_accept with acceptor==null");
7171
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   110
		return NULL;
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   111
	}
7175
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   112
	flib_tcpsocket result = NULL;
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   113
	TCPsocket sock = NULL;
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   114
	while(!result && (sock = SDLNet_TCP_Accept(acceptor->sock))) {
7171
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   115
		if(localOnly && !connection_is_local(sock)) {
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   116
			flib_log_i("Rejected nonlocal connection attempt from %s", flib_format_ip(get_peer_ip(sock)));
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   117
			SDLNet_TCP_Close(sock);
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   118
		} else {
7175
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   119
			result = flib_socket_create(sock);
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   120
			if(!result) {
7171
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   121
				SDLNet_TCP_Close(sock);
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   122
			}
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   123
		}
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   124
	}
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   125
	return result;
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   126
}
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   127
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   128
void flib_socket_close(flib_tcpsocket *sockptr) {
7175
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   129
	if(!sockptr) {
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   130
		flib_log_e("Call to flib_socket_close with sockptr==null");
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   131
	} else if(*sockptr) {
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   132
		flib_tcpsocket sock = *sockptr;
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   133
		SDLNet_DelSocket(sock->sockset, (SDLNet_GenericSocket)sock->sock);
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   134
		SDLNet_TCP_Close(sock->sock);
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   135
		SDLNet_FreeSocketSet(sock->sockset);
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   136
		free(sock);
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   137
		*sockptr = NULL;
7171
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   138
	}
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   139
}
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   140
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   141
int flib_socket_nbrecv(flib_tcpsocket sock, void *data, int maxlen) {
7175
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   142
	if(!sock || (maxlen>0 && !data)) {
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   143
		flib_log_e("Call to flib_socket_nbrecv with sock==null or data==null");
7171
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   144
		return -1;
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   145
	}
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   146
	int readySockets = SDLNet_CheckSockets(sock->sockset, 0);
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   147
	if(readySockets>0) {
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   148
		int size = SDLNet_TCP_Recv(sock->sock, data, maxlen);
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   149
		return size>0 ? size : -1;
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   150
	} else if(readySockets==0) {
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   151
		return 0;
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   152
	} else {
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   153
		flib_log_e("Error in select system call: %s", SDLNet_GetError());
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   154
		return -1;
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   155
	}
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   156
}
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   157
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   158
int flib_socket_send(flib_tcpsocket sock, void *data, int len) {
7175
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   159
	if(!sock || (len>0 && !data)) {
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   160
		flib_log_e("Call to flib_socket_send with sock==null or data==null");
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   161
		return -1;
038e3415100a Added ini reading/writing for game schemes to the frontend lib
Medo <smaxein@googlemail.com>
parents: 7171
diff changeset
   162
	}
7171
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   163
	return SDLNet_TCP_Send(sock->sock, data, len);
906e72caea7b frontlib refactoring
Medo <smaxein@googlemail.com>
parents:
diff changeset
   164
}