2
* TICKR - GTK-based Feed Reader - Copyright (C) Emmanuel Thomas-Maurin 2009-2012
3
* <manutm007@gmail.com>
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation, either version 3 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
#ifndef INC_TICKR_SOCKET_H
20
#define INC_TICKR_SOCKET_H
22
#define USE_PROXY_FLAG get_use_proxy()
23
#define WARNING(a1, a2, a3, a4, a5, a6) warning(a1, a2, a3, a4, a5, a6)
26
/* check these 2 values - need more testing (1s / 0.5s / 0.1.s) */
27
#define SEND_RECV_TIMEOUT_SEC 1
28
#define SEND_RECV_TIMEOUT_USEC 0
41
# include <sys/socket.h>
43
# include <arpa/inet.h>
44
# include <sys/select.h>
46
# define _WIN32_WINNT 0x0501 /* win version = xp or higher */
47
# include <winsock2.h>
48
# include <ws2tcpip.h>
50
# include <iphlpapi.h>
54
#include "../libetm-0.4.3/libetm.h"
56
#define CONNECT_TIMEOUT 5
57
#define RECV_CHUNK_LEN (16 * 1024 - 1)
61
# define SOCK_CREATE_ERROR -1 /* socket() */
62
# define SOCK_FUNC_ERROR -1 /* setsockopt(), bind(), listen(), select(), connect(),
63
* send(), recv(), fnctl(), ioctlsocket() */
64
# define CLOSE_SOCK(s) close(s)
67
# define SOCK_CREATE_ERROR INVALID_SOCKET
68
# define SOCK_FUNC_ERROR SOCKET_ERROR
69
# define CLOSE_SOCK(s) closesocket(s)
73
SOCK_ERROR = LIBETM_LASTERRORCODE + 1,
75
SOCK_SHOULD_BE_CLOSED,
85
CONNECTION_CLOSED_BY_SERVER,
90
#define FPRINTF_FFLUSH_2(a1, a2); {fprintf(a1, a2);fflush(a1);}
91
#define FPRINTF_FFLUSH_3(a1, a2, a3); {fprintf(a1, a2, a3);fflush(a1);}
92
#define FPRINTF_FFLUSH_4(a1, a2, a3, a4); {fprintf(a1, a2, a3, a4);fflush(a1);}
95
* open stream socket in non-blocking mode and connect to host
96
* return socket fd (> 0) / SOCK_CREATE_ERROR (-1 on Linux) if error
98
sockt connect_to_host(const char *, const char *);
100
int writable_data_is_available_on_socket(sockt);
102
int readable_data_is_available_on_socket(sockt);
105
* return n bytes sent or SOCK_FUNC_ERROR (-1 on Linux) if error (connection
106
* closed by server or ?)
108
int send_full(sockt, const char *);
111
* return response = recv_full(socket, &bytes_received, &status) or NULL if error
112
* -> status = SOCK_OK, CONNECTION_CLOSED_BY_SERVER, RECV_ERROR or SOCK_SHOULD_BE_CLOSED
113
* -> allocate memory for response (must be freed afterwards with free2() if != NULL)
115
char *recv_full(sockt, int *, int *);
118
const char *win32_error_msg(int);
121
const char *sock_error_message();
122
#endif /* INC_TICKR_SOCKET_H */