24#ifdef FREECIV_HAVE_SYS_TYPES_H
27#ifdef HAVE_SYS_SELECT_H
29#include <sys/select.h>
73 "Closing a socket (%s) before calling "
97 (*conn_close_callback) (pconn);
143 buffer->
ndata += didget;
146 }
else if (didget == 0) {
151#ifdef NONBLOCKING_SOCKETS
152 else if (errno == EWOULDBLOCK || errno == EAGAIN) {
167 int start, nput, nblock;
173 for (start = 0; buf->
ndata-start > limit;) {
174 fd_set writefs, exceptfs;
179 FD_SET(pc->
sock, &writefs);
180 FD_SET(pc->
sock, &exceptfs);
182 tv.tv_sec = 0; tv.tv_usec = 0;
184 if (
fc_select(pc->
sock + 1, NULL, &writefs, &exceptfs, &tv) <= 0) {
185 if (errno != EINTR) {
194 if (FD_ISSET(pc->
sock, &exceptfs)) {
199 if (FD_ISSET(pc->
sock, &writefs)) {
201 log_debug(
"trying to write %d limit=%d", nblock, limit);
203 (
const char *)buf->
data+start, nblock)) == -1) {
204#ifdef NONBLOCKING_SOCKETS
205 if (errno == EWOULDBLOCK || errno == EAGAIN) {
243#ifndef FREECIV_JSON_CONNECTION
260 const unsigned char *data,
int len)
287 const unsigned char *
data,
int len)
297#ifndef FREECIV_JSON_CONNECTION
301 log_verbose(
"cut connection %s due to huge send buffer (1)",
311 log_verbose(
"cut connection %s due to huge send buffer (2)",
325 if (pc && pc->
used) {
424 "Trying to look at the id of a non existing connection");
426 if (pconn->id ==
id) {
531 int result = old_request_id + 1;
533 if ((result & 0xffff) == 0) {
534 log_packet(
"INFORMATION: request_id has wrapped around; "
535 "setting from %d to 2", result);
548#ifdef USE_COMPRESSION
612#ifdef FREECIV_JSON_CONNECTION
613 pconn->json_mode =
TRUE;
618#ifdef USE_COMPRESSION
630 log_error(
"WARNING: Trying to close already closed connection");
693#ifdef USE_COMPRESSION
707#ifdef USE_COMPRESSION
719#ifdef USE_COMPRESSION
731#ifdef USE_COMPRESSION
819 const char *test = NULL;
821 switch (ppattern->
type) {
838 log_error(
"%s(): Invalid pattern type (%d)",
839 __FUNCTION__, ppattern->
type);
863 char *buf,
size_t buf_len)
866 conn_pattern_type_name(ppattern->
type),
876 enum conn_pattern_type prefer,
878 size_t error_buf_len)
880 enum conn_pattern_type
type;
884 if ((p = strchr(pattern,
'='))) {
886 const size_t pattern_type_len = ++p - pattern;
887 char pattern_type[pattern_type_len];
889 fc_strlcpy(pattern_type, pattern, pattern_type_len);
892 if (!conn_pattern_type_is_valid(
type)) {
893 if (NULL != error_buf) {
895 _(
"\"%s\" is not a valid pattern type"),
904 if (!conn_pattern_type_is_valid(
type)) {
905 if (NULL != error_buf) {
906 fc_strlcpy(error_buf,
_(
"Missing pattern type"), error_buf_len);
918 if (NULL != error_buf) {
919 fc_strlcpy(error_buf,
_(
"Missing pattern"), error_buf_len);
size_t conn_pattern_to_string(const struct conn_pattern *ppattern, char *buf, size_t buf_len)
static conn_close_fn_t conn_close_callback
struct player * conn_get_player(const struct connection *pconn)
void conn_list_do_unbuffer(struct conn_list *dest)
static void default_conn_close_callback(struct connection *pconn)
struct connection * conn_by_user_prefix(const char *user_name, enum m_pre_result *result)
bool can_conn_edit(const struct connection *pconn)
struct connection * conn_by_user(const char *user_name)
void conn_list_compression_thaw(const struct conn_list *pconn_list)
void connections_set_close_callback(conn_close_fn_t func)
static void flush_connection_send_buffer_packets(struct connection *pc)
static const char * connection_accessor(int i)
void flush_connection_send_buffer_all(struct connection *pc)
int get_next_request_id(int old_request_id)
struct socket_packet_buffer * new_socket_packet_buffer(void)
void conn_list_do_buffer(struct conn_list *dest)
bool can_conn_enable_editing(const struct connection *pconn)
void connection_do_buffer(struct connection *pc)
static bool add_connection_data(struct connection *pconn, const unsigned char *data, int len)
bool conn_pattern_match(const struct conn_pattern *ppattern, const struct connection *pconn)
static bool buffer_ensure_free_extra_space(struct socket_packet_buffer *buf, int extra_space)
void conn_set_capability(struct connection *pconn, const char *capability)
static void init_packet_hashes(struct connection *pc)
void conn_pattern_destroy(struct conn_pattern *ppattern)
void conn_reset_delta_state(struct connection *pc)
void connection_common_init(struct connection *pconn)
void connection_close(struct connection *pconn, const char *reason)
void conn_list_compression_freeze(const struct conn_list *pconn_list)
struct conn_pattern * conn_pattern_new(enum conn_pattern_type type, const char *wildcard)
bool conn_controls_player(const struct connection *pconn)
bool conn_is_global_observer(const struct connection *pconn)
const char * conn_description(const struct connection *pconn)
void connection_common_close(struct connection *pconn)
struct conn_pattern * conn_pattern_from_string(const char *pattern, enum conn_pattern_type prefer, char *error_buf, size_t error_buf_len)
void conn_compression_freeze(struct connection *pconn)
static void free_packet_hashes(struct connection *pc)
static void free_socket_packet_buffer(struct socket_packet_buffer *buf)
struct connection * conn_by_number(int id)
void free_compression_queue(struct connection *pc)
const char blank_addr_str[]
int read_socket_data(int sock, struct socket_packet_buffer *buffer)
bool connection_send_data(struct connection *pconn, const unsigned char *data, int len)
static int write_socket_data(struct connection *pc, struct socket_packet_buffer *buf, int limit)
enum cmdlevel conn_get_access(const struct connection *pconn)
bool conn_is_valid(const struct connection *pconn)
bool conn_compression_frozen(const struct connection *pconn)
bool conn_pattern_list_match(const struct conn_pattern_list *plist, const struct connection *pconn)
void connection_do_unbuffer(struct connection *pc)
#define conn_pattern_list_iterate_end
void(* conn_close_fn_t)(struct connection *pconn)
bool conn_compression_thaw(struct connection *pconn)
#define conn_list_iterate(connlist, pconn)
#define conn_pattern_list_iterate(plist, ppatern)
#define conn_list_iterate_end
static bool is_server(void)
void genhash_destroy(struct genhash *pgenhash)
void genhash_clear(struct genhash *pgenhash)
#define fc_assert_msg(condition, message,...)
#define fc_assert_ret(condition)
#define log_verbose(message,...)
#define fc_assert(condition)
#define log_debug(message,...)
#define log_error(message,...)
#define fc_realloc(ptr, sz)
void fc_closesocket(int sock)
int fc_readsocket(int sock, void *buf, size_t size)
int fc_writesocket(int sock, const void *buf, size_t size)
int fc_select(int n, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, fc_timeval *timeout)
struct timeval fc_timeval
void packet_header_init(struct packet_header *packet_header)
const struct packet_handlers * packet_handlers_initial(void)
const struct packet_handlers * packet_handlers_get(const char *capability)
bool packet_has_game_info_flag(enum packet_type type)
const char * player_name(const struct player *pplayer)
bool wildcard_fit_string(const char *pattern, const char *test)
enum m_pre_result match_prefix(m_pre_accessor_fn_t accessor_fn, size_t n_names, size_t max_len_name, m_pre_strncmp_fn_t cmp_fn, m_strlen_fn_t len_fn, const char *prefix, int *ind_result)
void remove_leading_trailing_spaces(char *s)
struct packet_game_info info
struct conn_list * all_connections
enum conn_pattern_type type
struct genhash ** received
struct connection::@61 statistics
enum cmdlevel access_level
const struct packet_handlers * handlers
struct connection::@59 phs
struct packet_header packet_header
char username[MAX_LEN_NAME]
struct connection::@57::@63 server
struct timer * last_write
struct connection::@60 compression
char ipaddr[MAX_LEN_ADDR]
struct socket_packet_buffer * send_buffer
char capability[MAX_LEN_CAPSTR]
void(* notify_of_writable_data)(struct connection *pc, bool data_available_and_socket_full)
struct socket_packet_buffer * buffer
int fc_snprintf(char *str, size_t n, const char *format,...)
size_t fc_strlcpy(char *dest, const char *src, size_t n)
int fc_strcasecmp(const char *str0, const char *str1)
int cat_snprintf(char *str, size_t n, const char *format,...)
int fc_strncasequotecmp(const char *str0, const char *str1, size_t n)
size_t effectivestrlenquote(const char *str)
#define sz_strlcpy(dest, src)
#define sz_strlcat(dest, src)
void timer_destroy(struct timer *t)
void timer_start(struct timer *t)
struct timer * timer_renew(struct timer *t, enum timer_timetype type, enum timer_use use)