예제 #1
0
파일: tls_prng_egd.c 프로젝트: 10jschen/acl
TLS_PRNG_SRC *tls_prng_egd_open(const char *name, int timeout)
{
    const char *myname = "tls_prng_egd_open";
    TLS_PRNG_SRC *egd;
    ACL_SOCKET     fd;

    if (acl_msg_verbose)
	acl_msg_info("%s: connect to EGD server %s", myname, name);

#ifdef ACL_UNIX
    fd = acl_unix_connect(name, ACL_BLOCKING, timeout);
#elif defined(ACL_MS_WINDOWS)
	fd = acl_inet_connect(name, ACL_BLOCKING, timeout);
#endif
	
	if (fd < 0) {
	if (acl_msg_verbose)
	    acl_msg_info("%s: cannot connect to EGD server %s: %s",
		myname, name, acl_last_serror());
	return (0);
    } else {
	egd = (TLS_PRNG_SRC *) acl_mymalloc(sizeof(*egd));
	egd->fd.sock = fd;
	egd->name = acl_mystrdup(name);
	egd->timeout = timeout;
	if (acl_msg_verbose)
	    acl_msg_info("%s: connected to EGD server %s", myname, name);
	return (egd);
    }
}
예제 #2
0
int acl_unix_trigger(ACL_EVENT *event, const char *service,
	const char *buf, int len, int timeout)
{
	const char *myname = "acl_unix_trigger";
	struct ACL_UNIX_TRIGGER *up;
	ACL_SOCKET fd;

	if (acl_msg_verbose > 0)
		acl_msg_info("%s: service %s", myname, service);

	/*
	 * Connect...
	 */
	if ((fd = acl_unix_connect(service, ACL_BLOCKING, timeout)) < 0) {
		if (acl_msg_verbose)
			acl_msg_warn("%s: connect to %s: %s",
				myname, service, strerror(errno));
		return -1;
	}
	acl_close_on_exec(fd, ACL_CLOSE_ON_EXEC);

	/*
	 * Stash away context.
	 */
	up = (struct ACL_UNIX_TRIGGER *) acl_mymalloc(sizeof(*up));
	up->service = acl_mystrdup(service);
	up->stream = acl_vstream_fdopen(fd, O_RDWR, 4096,
			timeout, ACL_VSTREAM_TYPE_LISTEN_UNIX);

	/*
	 * Write the request...
	 */
	if (acl_vstream_writen(up->stream, buf, len) < 0
		|| acl_vstream_writen(up->stream, "", 1) < 0)
	{
		if (acl_msg_verbose)
			acl_msg_warn("%s: write to %s: %s",
				myname, service, strerror(errno));
	}

	/*
	 * Wakeup when the peer disconnects, or when we lose patience.
	 */
#ifdef	__USE_TIMER
	if (timeout > 0)
		acl_event_request_timer(event, acl_unix_trigger_timer,
			(void *) up, (timeout + 100) * 1000000);
	acl_event_enable_read(event, up->stream, 0,
		acl_unix_trigger_event, (void *) up);
#else
	if (timeout > 0)
		acl_event_enable_read(event, up->stream, timeout + 100,
			acl_unix_trigger_event, (void *) up);
	else
		acl_event_enable_read(event, up->stream, 0,
			acl_unix_trigger_event, (void *) up);
#endif

	return 0;
}
예제 #3
0
		acl_msg_fatal("%s: addr null", myname);

	ptr = strchr(addr, ':');
	if (ptr != NULL) {
		connfd = acl_inet_connect_ex(addr, block_mode,
			connect_timeout, he_errorp);
	}
#ifdef WIN32
	else {
		acl_msg_error("%s(%d): addr(%s) invalid",
			myname, __LINE__, addr);
		return NULL;
	}
#elif defined(ACL_UNIX)
	else {
		connfd = acl_unix_connect(addr, block_mode, connect_timeout);
	}
#else
	else {
		connfd = ACL_SOCKET_INVALID;
	}
#endif

	if (connfd == ACL_SOCKET_INVALID)
		return NULL;
	client = acl_vstream_fdopen(connfd, ACL_VSTREAM_FLAG_RW,
			rw_bufsize, rw_timeout, ACL_VSTREAM_TYPE_SOCK);
	if (client == NULL) {
		acl_socket_close(connfd);
		return NULL;
	}