project_files/frontlib/socket.c
author Wuzzy <Wuzzy2@mail.ru>
Thu, 15 Mar 2018 21:15:16 +0100
changeset 13226 02bf6902eeb0
parent 10017 de822cd3df3a
permissions -rw-r--r--
Remove Qt SVG and Qt OpenGL as hard dependencies Qt SVG is not used in the frontend (no SVGs are rendered). Neither is Qt OpenGL used. Qt OpenGL is discouraged anyway.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10017
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
     1
/*
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
     2
 * Hedgewars, a free turn based strategy game
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
     3
 * Copyright (C) 2012 Simeon Maxein <smaxein@googlemail.com>
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
     4
 *
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
     5
 * This program is free software; you can redistribute it and/or
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
     6
 * modify it under the terms of the GNU General Public License
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
     7
 * as published by the Free Software Foundation; either version 2
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
     8
 * of the License, or (at your option) any later version.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
     9
 *
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    10
 * This program is distributed in the hope that it will be useful,
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    13
 * GNU General Public License for more details.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    14
 *
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    15
 * You should have received a copy of the GNU General Public License
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    16
 * along with this program; if not, write to the Free Software
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    18
 */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    19
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    20
#include "socket.h"
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    21
#include "util/logging.h"
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    22
#include "util/util.h"
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    23
#include <stdlib.h>
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    24
#include <SDL_net.h>
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    25
#include <time.h>
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    26
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    27
struct _flib_tcpsocket {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    28
    TCPsocket sock;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    29
    SDLNet_SocketSet sockset;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    30
};
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    31
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    32
struct _flib_acceptor {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    33
    TCPsocket sock;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    34
    uint16_t port;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    35
};
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    36
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    37
static uint32_t getPeerIp(TCPsocket sock) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    38
    IPaddress *addr = SDLNet_TCP_GetPeerAddress(sock);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    39
    return SDLNet_Read32(&addr->host);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    40
}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    41
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    42
static bool connectionIsLocal(TCPsocket sock) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    43
    return getPeerIp(sock) == (uint32_t)((127UL<<24)+1); // 127.0.0.1
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    44
}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    45
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    46
static flib_tcpsocket *createSocket(TCPsocket sdlsock) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    47
    flib_tcpsocket *result = flib_calloc(1, sizeof(flib_tcpsocket));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    48
    if(result) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    49
        result->sock = sdlsock;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    50
        result->sockset = SDLNet_AllocSocketSet(1);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    51
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    52
        if(!result->sockset) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    53
            flib_log_e("Can't allocate socket: Out of memory!");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    54
            SDLNet_FreeSocketSet(result->sockset);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    55
            free(result);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    56
            result = NULL;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    57
        } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    58
            SDLNet_AddSocket(result->sockset, (SDLNet_GenericSocket)result->sock);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    59
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    60
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    61
    return result;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    62
}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    63
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    64
TCPsocket listen(uint16_t port) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    65
    IPaddress addr;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    66
    addr.host = INADDR_ANY;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    67
    SDLNet_Write16(port, &addr.port);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    68
    TCPsocket sock = SDLNet_TCP_Open(&addr);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    69
    if(!sock) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    70
        flib_log_w("Unable to listen on port %u: %s", (unsigned)port, SDLNet_GetError());
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    71
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    72
    return sock;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    73
}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    74
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    75
flib_acceptor *flib_acceptor_create(uint16_t port) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    76
    flib_acceptor *result = flib_calloc(1, sizeof(flib_acceptor));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    77
    if(result) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    78
        if(port > 0) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    79
            result->port = port;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    80
            result->sock = listen(result->port);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    81
        } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    82
            /* SDL_net does not seem to have a way to listen on a random unused port
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    83
               and find out which port that is, so let's try to find one ourselves. */
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    84
            srand(time(NULL));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    85
            for(int i=0; !result->sock && i<1000; i++) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    86
                // IANA suggests using ports in the range 49152-65535 for things like this
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    87
                result->port = 49152+(rand()%(65536-49152));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    88
                result->sock = listen(result->port);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    89
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    90
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    91
        if(!result->sock) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    92
            flib_log_e("Failed to create acceptor.");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    93
            free(result);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    94
            result = NULL;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    95
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    96
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    97
    return result;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    98
}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
    99
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   100
uint16_t flib_acceptor_listenport(flib_acceptor *acceptor) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   101
    if(!acceptor) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   102
        flib_log_e("Call to flib_acceptor_listenport with acceptor==null");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   103
        return 0;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   104
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   105
    return acceptor->port;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   106
}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   107
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   108
void flib_acceptor_close(flib_acceptor *acceptor) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   109
    if(acceptor) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   110
        SDLNet_TCP_Close(acceptor->sock);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   111
        free(acceptor);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   112
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   113
}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   114
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   115
flib_tcpsocket *flib_socket_accept(flib_acceptor *acceptor, bool localOnly) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   116
    flib_tcpsocket *result = NULL;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   117
    if(!acceptor) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   118
        flib_log_e("Call to flib_socket_accept with acceptor==null");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   119
    } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   120
        TCPsocket sock = NULL;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   121
        while(!result && (sock = SDLNet_TCP_Accept(acceptor->sock))) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   122
            if(localOnly && !connectionIsLocal(sock)) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   123
                flib_log_i("Rejected nonlocal connection attempt from %s", flib_format_ip(getPeerIp(sock)));
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   124
            } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   125
                result = createSocket(sock);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   126
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   127
            if(!result) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   128
                SDLNet_TCP_Close(sock);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   129
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   130
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   131
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   132
    return result;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   133
}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   134
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   135
flib_tcpsocket *flib_socket_connect(const char *host, uint16_t port) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   136
    flib_tcpsocket *result = NULL;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   137
    if(!host || port==0) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   138
        flib_log_e("Invalid parameter in flib_socket_connect");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   139
    } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   140
        IPaddress ip;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   141
        if(SDLNet_ResolveHost(&ip,host,port)==-1) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   142
           flib_log_e("SDLNet_ResolveHost: %s\n", SDLNet_GetError());
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   143
        } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   144
            TCPsocket sock=SDLNet_TCP_Open(&ip);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   145
            if(!sock) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   146
                flib_log_e("SDLNet_TCP_Open: %s\n", SDLNet_GetError());
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   147
            } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   148
                result = createSocket(sock);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   149
                if(result) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   150
                    sock = NULL;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   151
                }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   152
            }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   153
            SDLNet_TCP_Close(sock);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   154
        }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   155
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   156
    return result;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   157
}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   158
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   159
void flib_socket_close(flib_tcpsocket *sock) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   160
    if(sock) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   161
        SDLNet_DelSocket(sock->sockset, (SDLNet_GenericSocket)sock->sock);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   162
        SDLNet_TCP_Close(sock->sock);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   163
        SDLNet_FreeSocketSet(sock->sockset);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   164
        free(sock);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   165
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   166
}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   167
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   168
int flib_socket_nbrecv(flib_tcpsocket *sock, void *data, int maxlen) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   169
    if(!sock || (maxlen>0 && !data)) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   170
        flib_log_e("Call to flib_socket_nbrecv with sock==null or data==null");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   171
        return -1;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   172
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   173
    int readySockets = SDLNet_CheckSockets(sock->sockset, 0);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   174
    if(readySockets>0) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   175
        int size = SDLNet_TCP_Recv(sock->sock, data, maxlen);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   176
        return size>0 ? size : -1;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   177
    } else if(readySockets==0) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   178
        return 0;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   179
    } else {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   180
        flib_log_e("Error in select system call: %s", SDLNet_GetError());
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   181
        return -1;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   182
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   183
}
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   184
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   185
int flib_socket_send(flib_tcpsocket *sock, const void *data, int len) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   186
    if(!sock || (len>0 && !data)) {
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   187
        flib_log_e("Call to flib_socket_send with sock==null or data==null");
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   188
        return -1;
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   189
    }
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   190
    return SDLNet_TCP_Send(sock->sock, data, len);
de822cd3df3a fixwhitespace and dos2unix
koda
parents: 8091
diff changeset
   191
}