CUBRID Engine  latest
tcp.c File Reference
#include "config.h"
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <signal.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <arpa/inet.h>
#include <sys/uio.h>
#include <sys/un.h>
#include <sys/ioctl.h>
#include <netinet/tcp.h>
#include <assert.h>
#include "porting.h"
#include "connection_cl.h"
#include "error_manager.h"
#include "connection_globals.h"
#include "system_parameter.h"
#include "environment_variable.h"
#include "tcp.h"
#include <pthread.h>

Go to the source code of this file.

Macros

#define HOST_ID_ARRAY_SIZE   8 /* size of the host_id string */
 
#define TCP_MIN_NUM_RETRIES   3
 
#define CONTROLLEN   (sizeof(struct cmsghdr) + sizeof(int))
 
#define INADDR_NONE   0xffffffff
 
#define SET_NONBLOCKING(fd)
 
#define SET_NONBLOCKING(fd)
 

Functions

static void css_sockopt (SOCKET sd)
 
static int css_sockaddr (const char *host, int port, struct sockaddr *saddr, socklen_t *slen)
 
static int css_fd_error (SOCKET fd)
 
int css_gethostname (char *name, size_t namelen)
 
char * css_get_master_domain_path (void)
 
SOCKET css_tcp_client_open (const char *host, int port)
 
int css_hostname_to_ip (const char *host, unsigned char *ip_addr)
 
SOCKET css_tcp_client_open_with_retry (const char *host, int port, bool will_retry)
 
SOCKET css_tcp_client_open_with_timeout (const char *host, int port, int timeout)
 
int css_tcp_master_open (int port, SOCKET *sockfd)
 
SOCKET css_master_accept (SOCKET sockfd)
 
bool css_tcp_setup_server_datagram (const char *pathname, SOCKET *sockfd)
 
bool css_tcp_listen_server_datagram (SOCKET sockfd, SOCKET *newfd)
 
bool css_tcp_master_datagram (char *path_name, SOCKET *sockfd)
 
SOCKET css_open_new_socket_from_master (SOCKET fd, unsigned short *rid)
 
bool css_transfer_fd (SOCKET server_fd, SOCKET client_fd, unsigned short rid, CSS_SERVER_REQUEST request_for_server)
 
void css_shutdown_socket (SOCKET fd)
 
unsigned int css_gethostid (void)
 
int css_open_server_connection_socket (void)
 
void css_close_server_connection_socket (void)
 
SOCKET css_server_accept (SOCKET sockfd)
 
int css_get_max_socket_fds (void)
 
static int in_cksum (u_short *addr, int len)
 
bool css_peer_alive (SOCKET sd, int timeout)
 
int css_get_peer_name (SOCKET sockfd, char *hostname, size_t len)
 
int css_get_sock_name (SOCKET sockfd, char *hostname, size_t len)
 

Variables

static pthread_mutex_t gethostbyname_lock = PTHREAD_MUTEX_INITIALIZER
 
static const int css_Maximum_server_count = 1000
 

Macro Definition Documentation

#define CONTROLLEN   (sizeof(struct cmsghdr) + sizeof(int))

Definition at line 87 of file tcp.c.

Referenced by css_open_new_socket_from_master(), css_transfer_fd(), recv_fd(), and send_fd().

#define HOST_ID_ARRAY_SIZE   8 /* size of the host_id string */

Definition at line 85 of file tcp.c.

#define INADDR_NONE   0xffffffff
#define SET_NONBLOCKING (   fd)
Value:
{ \
int flags = fcntl (fd, F_GETFL); \
flags |= O_NONBLOCK; \
fcntl (fd, F_SETFL, flags); \
}

Definition at line 1320 of file tcp.c.

Referenced by css_peer_alive(), css_tcp_client_open_with_timeout(), and in_cksum().

#define SET_NONBLOCKING (   fd)
Value:
{ \
int flags = fcntl (fd, F_GETFL); \
flags |= O_NONBLOCK; \
fcntl (fd, F_SETFL, flags); \
}

Definition at line 1320 of file tcp.c.

#define TCP_MIN_NUM_RETRIES   3

Definition at line 86 of file tcp.c.

Referenced by css_tcp_client_open_with_retry(), and css_tcp_master_datagram().

Function Documentation

void css_close_server_connection_socket ( void  )

Definition at line 1242 of file tcp.c.

Referenced by css_init().

Here is the caller graph for this function:

static int css_fd_error ( SOCKET  fd)
static

Definition at line 1267 of file tcp.c.

References cubregex::count(), and rc.

char* css_get_master_domain_path ( void  )

Definition at line 155 of file tcp.c.

References envvar_get(), envvar_prefix(), NULL, and prm_get_master_port_id().

Referenced by css_master_cleanup(), css_process_kill_master(), css_sockaddr(), and css_tcp_master_open().

Here is the caller graph for this function:

int css_get_max_socket_fds ( void  )

Definition at line 1315 of file tcp.c.

Referenced by crash_handler(), css_daemon_start(), and sysprm_final().

Here is the caller graph for this function:

int css_get_peer_name ( SOCKET  sockfd,
char *  hostname,
size_t  len 
)

Definition at line 1592 of file tcp.c.

Referenced by css_process_deact_stop_all(), css_process_deactivate_heartbeat(), and css_send_error().

Here is the caller graph for this function:

int css_get_sock_name ( SOCKET  sockfd,
char *  hostname,
size_t  len 
)

Definition at line 1618 of file tcp.c.

Referenced by css_send_error().

Here is the caller graph for this function:

unsigned int css_gethostid ( void  )

Definition at line 1209 of file tcp.c.

Referenced by log_2pc_make_global_tran_id().

Here is the caller graph for this function:

int css_gethostname ( char *  name,
size_t  namelen 
)

Definition at line 114 of file tcp.c.

int css_hostname_to_ip ( const char *  host,
unsigned char *  ip_addr 
)

Definition at line 227 of file tcp.c.

Referenced by boot_make_session_server_key().

Here is the caller graph for this function:

SOCKET css_master_accept ( SOCKET  sockfd)

Definition at line 836 of file tcp.c.

Referenced by css_check_master_socket_input().

Here is the caller graph for this function:

SOCKET css_open_new_socket_from_master ( SOCKET  fd,
unsigned short *  rid 
)

Definition at line 1059 of file tcp.c.

Referenced by css_process_new_client().

Here is the caller graph for this function:

int css_open_server_connection_socket ( void  )

Definition at line 1228 of file tcp.c.

Referenced by css_connect_to_master_server().

Here is the caller graph for this function:

bool css_peer_alive ( SOCKET  sd,
int  timeout 
)

Definition at line 1470 of file tcp.c.

References ARG_FILE_LINE, css_ping(), er_log_debug, htons(), and SET_NONBLOCKING.

Referenced by css_connection_handler_thread(), and css_net_recv().

Here is the caller graph for this function:

SOCKET css_server_accept ( SOCKET  sockfd)

Definition at line 1256 of file tcp.c.

Referenced by css_is_shutdown_timeout_expired().

Here is the caller graph for this function:

void css_shutdown_socket ( SOCKET  fd)
static int css_sockaddr ( const char *  host,
int  port,
struct sockaddr *  saddr,
socklen_t *  slen 
)
static
SOCKET css_tcp_client_open ( const char *  host,
int  port 
)

Definition at line 182 of file tcp.c.

Referenced by css_common_connect().

Here is the caller graph for this function:

SOCKET css_tcp_client_open_with_retry ( const char *  host,
int  port,
bool  will_retry 
)

Definition at line 414 of file tcp.c.

Referenced by css_common_connect(), css_does_master_exist(), and css_tcp_client_open().

Here is the caller graph for this function:

SOCKET css_tcp_client_open_with_timeout ( const char *  host,
int  port,
int  timeout 
)
bool css_tcp_listen_server_datagram ( SOCKET  sockfd,
SOCKET newfd 
)

Definition at line 930 of file tcp.c.

Referenced by css_connect_to_master_server().

Here is the caller graph for this function:

bool css_tcp_master_datagram ( char *  path_name,
SOCKET sockfd 
)

Definition at line 967 of file tcp.c.

Referenced by css_accept_new_request(), and css_accept_old_request().

Here is the caller graph for this function:

int css_tcp_master_open ( int  port,
SOCKET sockfd 
)

Definition at line 663 of file tcp.c.

Referenced by css_master_init().

Here is the caller graph for this function:

bool css_tcp_setup_server_datagram ( const char *  pathname,
SOCKET sockfd 
)
bool css_transfer_fd ( SOCKET  server_fd,
SOCKET  client_fd,
unsigned short  rid,
CSS_SERVER_REQUEST  request_for_server 
)

Definition at line 1122 of file tcp.c.

Referenced by css_send_new_request_to_server().

Here is the caller graph for this function:

static int in_cksum ( u_short *  addr,
int  len 
)
static

Definition at line 1330 of file tcp.c.

References ARG_FILE_LINE, css_ping(), er_log_debug, htons(), ntohs(), NULL, pid, and SET_NONBLOCKING.

Variable Documentation

const int css_Maximum_server_count = 1000
static

Definition at line 92 of file tcp.c.

Referenced by css_tcp_master_open().

pthread_mutex_t gethostbyname_lock = PTHREAD_MUTEX_INITIALIZER
static

Definition at line 82 of file tcp.c.

Referenced by css_hostname_to_ip(), css_sockaddr(), and hb_hostname_to_sin_addr().