Beispiel #1
0
static long
vrrp_timer_fd(const int fd)
{
	timeval_t timer, vrrp_timer;
	long vrrp_long;

	timer = vrrp_compute_timer(fd);
	vrrp_timer = timer_sub(timer, time_now);
	vrrp_long = timer_long(vrrp_timer);

	return (vrrp_long < 0) ? TIMER_MAX_SEC : vrrp_long;
}
Beispiel #2
0
enum connect_result
tcp_socket_state(int fd, thread_t * thread, char *ipaddress, uint16_t addr_port,
		 int (*func) (thread_t *))
{
	int status;
	socklen_t slen;
	int ret = 0;
	timeval_t timer_min;

	/* Handle connection timeout */
	if (thread->type == THREAD_WRITE_TIMEOUT) {
		DBG("TCP connection timeout to [%s]:%d.\n",
		    ipaddress, ntohs(addr_port));
		close(thread->u.fd);
		return connect_timeout;
	}

	/* Check file descriptor */
	slen = sizeof (status);
	if (getsockopt
	    (thread->u.fd, SOL_SOCKET, SO_ERROR, (void *) &status, &slen) < 0)
		ret = errno;

	/* Connection failed !!! */
	if (ret) {
		DBG("TCP connection failed to [%s]:%d.\n",
		    ipaddress, ntohs(addr_port));
		close(thread->u.fd);
		return connect_error;
	}

	/* If status = 0, TCP connection to remote host is established.
	 * Otherwise register checker thread to handle connection in progress,
	 * and other error code until connection is established.
	 * Recompute the write timeout (or pending connection).
	 */
	if (status != 0) {
		DBG("TCP connection to [%s]:%d still IN_PROGRESS.\n",
		    ipaddress, ntohs(addr_port));

		timer_min = timer_sub_now(thread->sands);
		thread_add_write(thread->master, func, THREAD_ARG(thread)
				 , thread->u.fd, timer_long(timer_min));
		return connect_in_progress;
	}

	return connect_success;
}