Beispiel #1
0
/* set send event. */
void eventmgr_setup_socket_send_event(struct socketer *self) {
	struct kevent ev;

	assert(catomic_read(&self->sendlock) == 1);
	if (catomic_read(&self->sendlock) != 1) {
		log_error("%x socket recvlock:%d, sendlock:%d, fd:%d, ref:%d, thread_id:%d", 
				self, (int)catomic_read(&self->recvlock), (int)catomic_read(&self->sendlock), 
				self->sockfd, (int)catomic_read(&self->ref), cthread_self_id());
	}

	EV_SET(&ev, self->sockfd, EVFILT_WRITE, EV_ENABLE, 0, 0, self);
	if (kevent(s_mgr->kqueue_fd, &ev, 1, NULL, 0, NULL) == -1) {
		/*log_error("kqueue, setup send event to kqueue set on fd %d error!, errno:%d", self->sockfd, NET_GetLastError());*/
		socketer_close(self);
		if (catomic_dec(&self->ref) < 1) {
			log_error("%x socket recvlock:%d, sendlock:%d, fd:%d, ref:%d, thread_id:%d, connect:%d, deleted:%d", 
					self, (int)catomic_read(&self->recvlock), (int)catomic_read(&self->sendlock), self->sockfd, 
					(int)catomic_read(&self->ref), cthread_self_id(), self->connected, self->deleted);
		}
	}
	debuglog("setup send event to eventmgr.");
}
Beispiel #2
0
/* remove send event. */
void eventmgr_remove_socket_send_event(struct socketer *self) {
	struct kevent ev;

	assert(catomic_read(&self->sendlock) == 1);
	if (catomic_read(&self->sendlock) != 1) {
		log_error("%x socket recvlock:%d, sendlock:%d, fd:%d, ref:%d, thread_id:%d", 
				self, (int)catomic_read(&self->recvlock), (int)catomic_read(&self->sendlock), 
				self->sockfd, (int)catomic_read(&self->ref), cthread_self_id());
	}

	EV_SET(&ev, self->sockfd, EVFILT_WRITE, EV_DISABLE, 0, 0, self);
	if (kevent(s_mgr->kqueue_fd, &ev, 1, NULL, 0, NULL) == -1) {
		/*log_error("kqueue, remove send event from kqueue set on fd %d error!, errno:%d", self->sockfd, NET_GetLastError());*/
		socketer_close(self);
	}
	debuglog("remove send event from eventmgr.");
}
Beispiel #3
0
static unsigned __stdcall
#else
static void *
#endif
thread_run_func(void *data) {
	cthread self = (cthread)data;

	self->thread_id = cthread_self_id();

	self->state = eState_Run;
	self->func_run(&self);

	self->state = eState_Exit;

#ifdef _WIN32
	return 0;
#else
	return NULL;
#endif
}