Blame genhash/sock.c

Packit c22fc9
/*
Packit c22fc9
 * Soft:        Perform a GET query to a remote HTTP/HTTPS server.
Packit c22fc9
 *              Set a timer to compute global remote server response
Packit c22fc9
 *              time.
Packit c22fc9
 *
Packit c22fc9
 * Part:        Socket pool utility functions.
Packit c22fc9
 *
Packit c22fc9
 * Authors:     Alexandre Cassen, <acassen@linux-vs.org>
Packit c22fc9
 *
Packit c22fc9
 *              This program is distributed in the hope that it will be useful,
Packit c22fc9
 *              but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit c22fc9
 *              MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Packit c22fc9
 *              See the GNU General Public License for more details.
Packit c22fc9
 *
Packit c22fc9
 *              This program is free software; you can redistribute it and/or
Packit c22fc9
 *              modify it under the terms of the GNU General Public License
Packit c22fc9
 *              as published by the Free Software Foundation; either version
Packit c22fc9
 *              2 of the License, or (at your option) any later version.
Packit c22fc9
 *
Packit c22fc9
 * Copyright (C) 2001-2017 Alexandre Cassen, <acassen@gmail.com>
Packit c22fc9
 */
Packit c22fc9
Packit c22fc9
#include "config.h"
Packit c22fc9
Packit c22fc9
/* system includes */
Packit c22fc9
Packit c22fc9
/* keepalived includes */
Packit c22fc9
#include "memory.h"
Packit c22fc9
Packit c22fc9
/* genhash includes */
Packit c22fc9
#include "include/sock.h"
Packit c22fc9
#include "include/layer4.h"
Packit c22fc9
Packit c22fc9
/* global var */
Packit c22fc9
SOCK *sock = NULL;
Packit c22fc9
Packit c22fc9
/* Close the descriptor */
Packit c22fc9
static void
Packit c22fc9
close_sock(SOCK * sock_obj)
Packit c22fc9
{
Packit c22fc9
	if (sock_obj->ssl) {
Packit c22fc9
		SSL_shutdown(sock_obj->ssl);
Packit c22fc9
		SSL_free(sock_obj->ssl);
Packit c22fc9
	}
Packit c22fc9
	close(sock_obj->fd);
Packit c22fc9
}
Packit c22fc9
Packit c22fc9
/* Destroy the socket handler */
Packit c22fc9
void
Packit c22fc9
free_sock(SOCK * sock_obj)
Packit c22fc9
{
Packit Service dfccb1
#ifdef _GENHASH_DEBUG_
Packit Service dfccb1
	fprintf(stderr, "Freeing fd:%d\n", sock_obj->fd);
Packit Service dfccb1
#endif
Packit c22fc9
Packit c22fc9
	close_sock(sock_obj);
Packit c22fc9
	FREE(sock_obj);
Packit c22fc9
}
Packit c22fc9
Packit c22fc9
/* Init socket handler */
Packit c22fc9
void
Packit c22fc9
init_sock(void)
Packit c22fc9
{
Packit c22fc9
	sock = (SOCK *) MALLOC(sizeof (SOCK));
Packit c22fc9
	memset(sock, 0, sizeof (SOCK));
Packit c22fc9
	thread_add_event(master, tcp_connect_thread, sock, 0);
Packit c22fc9
}