Window::Window(long left, long top, long right, long bottom) : fShowLevel(0), fCanvasList(0) { int windowServerPort; windowServerPort = namer_find ("window_server", 0); if (windowServerPort <= 0) { printf("couldn't connect to window server\n"); return; } int localReplyPort = port_create(0, "client_syncport"); fEventPort = port_create(0, "client_eventport"); fConnection = new Connection(windowServerPort, localReplyPort); fConnection->WriteInt8(OP_CREATE_WINDOW); fConnection->WriteInt32(0); // Child of root window fConnection->WriteInt32(left); fConnection->WriteInt32(top); fConnection->WriteInt32(right); fConnection->WriteInt32(bottom); fConnection->WriteInt32(fEventPort); fConnection->Flush(); fID = fConnection->ReadInt32(); fLock = qsem_create(1); thr_create((void*) EventLoop, this, "win_thread"); }
static void* evport_init(struct event_base *base) { struct evport_data *evpd; if (!(evpd = mm_calloc(1, sizeof(struct evport_data)))) return (NULL); if ((evpd->ed_port = port_create()) == -1) { mm_free(evpd); return (NULL); } if (grow(evpd, INITIAL_EVENTS_PER_GETN) < 0) { close(evpd->ed_port); mm_free(evpd); return NULL; } evpd->ed_npending = 0; evsig_init_(base); return (evpd); }
void SelEpolKqEvPrt::initialize(SOCKET sockfd, const int& timeout) { this->timeoutMilis = timeout; this->sockfd = sockfd; if(sockfd<=0) { listenerMode = false; sockfd = 0; } else { listenerMode = true; } curfds = 1; #if defined(USE_WIN_IOCP) initIOCP(); #elif defined(USE_MINGW_SELECT) fdMax = sockfd; FD_ZERO(&readfds); FD_ZERO(&master); #elif defined(USE_SELECT) fdsetSize = MAXDESCRIPTORS/FD_SETSIZE; fdMax = sockfd; for (int var = 0; var < fdsetSize; ++var) { FD_ZERO(&readfds[var]); FD_ZERO(&master[var]); } #elif defined USE_EPOLL epoll_handle = epoll_create(MAXDESCRIPTORS); memset(&ev, 0, sizeof(ev)); #elif defined USE_KQUEUE kq = kqueue(); if (kq == -1) { perror("kqueue"); } #elif defined USE_DEVPOLL if((dev_poll_fd = open("/dev/poll", O_RDWR)) <0) { perror("devpoll"); } if (fcntl(dev_poll_fd, F_SETFD, FD_CLOEXEC) < 0) { perror("devpoll fcntl"); } #elif defined USE_EVPORT if ((port = port_create()) < 0) { perror("port_create"); } #elif defined USE_POLL nfds=1; polled_fds = (struct pollfd *)calloc(1, nfds*sizeof(struct pollfd)); polled_fds->fd = descriptor; polled_fds->events = POLLIN | POLLPRI; return; #endif #if !defined(USE_WIN_IOCP) if(sockfd>0)registerForEvent(sockfd); #endif }
RTDECL(int) RTFileAioCtxCreate(PRTFILEAIOCTX phAioCtx, uint32_t cAioReqsMax, uint32_t fFlags) { int rc = VINF_SUCCESS; PRTFILEAIOCTXINTERNAL pCtxInt; AssertPtrReturn(phAioCtx, VERR_INVALID_POINTER); AssertReturn(!(fFlags & ~RTFILEAIOCTX_FLAGS_VALID_MASK), VERR_INVALID_PARAMETER); pCtxInt = (PRTFILEAIOCTXINTERNAL)RTMemAllocZ(sizeof(RTFILEAIOCTXINTERNAL)); if (RT_UNLIKELY(!pCtxInt)) return VERR_NO_MEMORY; /* Init the event handle. */ pCtxInt->iPort = port_create(); if (RT_LIKELY(pCtxInt->iPort > 0)) { pCtxInt->fFlags = fFlags; pCtxInt->u32Magic = RTFILEAIOCTX_MAGIC; *phAioCtx = (RTFILEAIOCTX)pCtxInt; } else { RTMemFree(pCtxInt); rc = RTErrConvertFromErrno(errno); } return rc; }
static int init_evports_per_thread() { int fd; evports_evlist_max = global.tune.maxpollevents; evports_evlist = calloc(evports_evlist_max, sizeof (port_event_t)); if (evports_evlist == NULL) { goto fail_alloc; } if (MAX_THREADS > 1 && tid) { if ((evports_fd[tid] = port_create()) == -1) { goto fail_fd; } } /* we may have to unregister some events initially registered on the * original fd when it was alone, and/or to register events on the new * fd for this thread. Let's just mark them as updated, the poller will * do the rest. */ for (fd = 0; fd < global.maxsock; fd++) updt_fd_polling(fd); return 1; fail_fd: free(evports_evlist); evports_evlist = NULL; evports_evlist_max = 0; fail_alloc: return 0; }
int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle, const char* filename, uv_fs_event_cb cb, int flags) { int portfd; loop->counters.fs_event_init++; /* We don't support any flags yet. */ assert(!flags); if ((portfd = port_create()) == -1) { uv__set_sys_error(loop, errno); return -1; } uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT); handle->filename = strdup(filename); handle->fd = portfd; handle->cb = cb; memset(&handle->fo, 0, sizeof handle->fo); handle->fo.fo_name = handle->filename; uv__fs_event_rearm(handle); ev_io_init(&handle->event_watcher, uv__fs_event_read, portfd, EV_READ); ev_io_start(loop->ev, &handle->event_watcher); ev_unref(loop->ev); return 0; }
int ioevent_init(IOEventPoller *ioevent, const int size, const int timeout_ms, const int extra_events) { int bytes; ioevent->size = size; ioevent->extra_events = extra_events; ioevent->iterator.index = 0; ioevent->iterator.count = 0; #if IOEVENT_USE_EPOLL ioevent->poll_fd = epoll_create(ioevent->size); bytes = sizeof(struct epoll_event) * size; ioevent->events = (struct epoll_event *)malloc(bytes); #elif IOEVENT_USE_KQUEUE ioevent->poll_fd = kqueue(); bytes = sizeof(struct kevent) * size; ioevent->events = (struct kevent *)malloc(bytes); ioevent->care_events = 0; #elif IOEVENT_USE_PORT ioevent->poll_fd = port_create(); bytes = sizeof(port_event_t) * size; ioevent->events = (port_event_t *)malloc(bytes); #endif if (ioevent->events == NULL) { return errno != 0 ? errno : ENOMEM; } ioevent_set_timeout(ioevent, timeout_ms); return 0; }
void ph_nbio_emitter_init(struct ph_nbio_emitter *emitter) { struct sigevent sev; port_notify_t notify; struct itimerspec ts; emitter->io_fd = port_create(); if (emitter->io_fd == -1) { ph_panic("port_create: `Pe%d", errno); } memset(&sev, 0, sizeof(sev)); memset(¬ify, 0, sizeof(notify)); memset(&ts, 0, sizeof(ts)); ts.it_interval.tv_nsec = WHEEL_INTERVAL_MS * 1000000; ts.it_value.tv_nsec = ts.it_interval.tv_nsec; notify.portnfy_port = emitter->io_fd; sev.sigev_notify = SIGEV_PORT; sev.sigev_value.sival_ptr = ¬ify; if (timer_create(CLOCK_REALTIME, &sev, &emitter->port_timer)) { ph_panic("failed to create timer: `Pe%d", errno); } if (timer_settime(emitter->port_timer, 0, &ts, NULL)) { ph_panic("failed to set timer: `Pe%d", errno); } }
int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle, const char* filename, uv_fs_event_cb cb, int flags) { int portfd; int first_run = 0; if (loop->fs_fd == -1) { if ((portfd = port_create()) == -1) { uv__set_sys_error(loop, errno); return -1; } loop->fs_fd = portfd; first_run = 1; } uv__handle_init(loop, (uv_handle_t*)handle, UV_FS_EVENT); uv__handle_start(handle); /* FIXME shouldn't start automatically */ handle->filename = strdup(filename); handle->fd = PORT_UNUSED; handle->cb = cb; memset(&handle->fo, 0, sizeof handle->fo); handle->fo.fo_name = handle->filename; uv__fs_event_rearm(handle); if (first_run) { uv__io_init(&loop->fs_event_watcher, uv__fs_event_read, portfd); uv__io_start(loop, &loop->fs_event_watcher, UV__POLLIN); } return 0; }
static apr_status_t impl_pollcb_create(apr_pollcb_t *pollcb, apr_uint32_t size, apr_pool_t *p, apr_uint32_t flags) { pollcb->fd = port_create(); if (pollcb->fd < 0) { return apr_get_netos_error(); } { int flags; if ((flags = fcntl(pollcb->fd, F_GETFD)) == -1) return errno; flags |= FD_CLOEXEC; if (fcntl(pollcb->fd, F_SETFD, flags) == -1) return errno; } pollcb->pollset.port = apr_palloc(p, size * sizeof(port_event_t)); apr_pool_cleanup_register(p, pollcb, cb_cleanup, apr_pool_cleanup_null); return APR_SUCCESS; }
static void* evport_init(struct event_base *base) { struct evport_data *evpd; int i; if (!(evpd = mm_calloc(1, sizeof(struct evport_data)))) return (NULL); if ((evpd->ed_port = port_create()) == -1) { mm_free(evpd); return (NULL); } /* * Initialize file descriptor structure */ evpd->ed_fds = mm_calloc(DEFAULT_NFDS, sizeof(struct fd_info)); if (evpd->ed_fds == NULL) { close(evpd->ed_port); mm_free(evpd); return (NULL); } evpd->ed_nevents = DEFAULT_NFDS; for (i = 0; i < EVENTS_PER_GETN; i++) evpd->ed_pending[i] = -1; evsig_init(base); return (evpd); }
int uv_fs_event_start(uv_fs_event_t* handle, uv_fs_event_cb cb, const char* filename, unsigned int flags) { int portfd; int first_run; if (uv__is_active(handle)) return -EINVAL; first_run = 0; if (handle->loop->fs_fd == -1) { portfd = port_create(); if (portfd == -1) return -errno; handle->loop->fs_fd = portfd; first_run = 1; } uv__handle_start(handle); handle->filename = strdup(filename); handle->fd = PORT_UNUSED; handle->cb = cb; memset(&handle->fo, 0, sizeof handle->fo); handle->fo.fo_name = handle->filename; uv__fs_event_rearm(handle); /* FIXME(bnoordhuis) Check return code. */ if (first_run) { uv__io_init(&handle->loop->fs_event_watcher, uv__fs_event_read, portfd); uv__io_start(handle->loop, &handle->loop->fs_event_watcher, UV__POLLIN); } return 0; }
/* Reopen the port handle when our pid changes. */ static int port_check_reopen(struct port_event_context *port_ev) { struct tevent_fd *fde; if (port_ev->pid == getpid()) { return 0; } close(port_ev->port_fd); port_ev->port_fd = port_create(); if (port_ev->port_fd == -1) { tevent_debug(port_ev->ev, TEVENT_DEBUG_FATAL, "port_create() failed"); return -1; } if (!ev_set_close_on_exec(port_ev->port_fd)) { tevent_debug(port_ev->ev, TEVENT_DEBUG_WARNING, "Failed to set close-on-exec, file descriptor may be leaked to children.\n"); } port_ev->pid = getpid(); for (fde=port_ev->ev->fd_events;fde;fde=fde->next) { fde->additional_flags &= PORT_ADDITIONAL_FD_FLAG_HAS_ASSOCIATION; if (port_update_event(port_ev, fde) != 0) { return -1; } } return 0; }
PortsEngine::PortsEngine() { int max = ulimit(4, 0); if (max > 0) { MAX_DESCRIPTORS = max; } else { ServerInstance->Logs->Log("SOCKET", LOG_DEFAULT, "ERROR: Can't determine maximum number of open sockets!"); std::cout << "ERROR: Can't determine maximum number of open sockets!" << std::endl; ServerInstance->Exit(EXIT_STATUS_SOCKETENGINE); } EngineHandle = port_create(); if (EngineHandle == -1) { ServerInstance->Logs->Log("SOCKET", LOG_SPARSE, "ERROR: Could not initialize socket engine: %s", strerror(errno)); ServerInstance->Logs->Log("SOCKET", LOG_SPARSE, "ERROR: This is a fatal error, exiting now."); std::cout << "ERROR: Could not initialize socket engine: " << strerror(errno) << std::endl; std::cout << "ERROR: This is a fatal error, exiting now." << std::endl; ServerInstance->Exit(EXIT_STATUS_SOCKETENGINE); } CurrentSetSize = 0; ref = new EventHandler* [GetMaxFds()]; events = new port_event_t[GetMaxFds()]; memset(ref, 0, GetMaxFds() * sizeof(EventHandler*)); }
void wait_init() { struct rlimit fd_new; (void) getrlimit(RLIMIT_NOFILE, &init_fd_rlimit); (void) getrlimit(RLIMIT_NOFILE, &fd_new); fd_new.rlim_max = fd_new.rlim_cur = WAIT_FILES; (void) setrlimit(RLIMIT_NOFILE, &fd_new); if ((port_fd = port_create()) == -1) uu_die("wait_init couldn't port_create"); wait_info_pool = uu_list_pool_create("wait_info", sizeof (wait_info_t), offsetof(wait_info_t, wi_link), NULL, UU_LIST_POOL_DEBUG); if (wait_info_pool == NULL) uu_die("wait_init couldn't create wait_info_pool"); wait_info_list = uu_list_create(wait_info_pool, wait_info_list, 0); if (wait_info_list == NULL) uu_die("wait_init couldn't create wait_info_list"); (void) pthread_mutex_init(&wait_info_lock, &mutex_attrs); }
void __libc_init_vfs (void) { vfs_public_port = namer_find ("vfs", 1); vfs_local_port = port_create (vfs_public_port,"vfs_public_port"); filename_area = area_create (0x1000, 0, (void **) &nameptr, 0); __vfs_openconn (vfs_local_port, filename_area); }
ACP_EXPORT acp_rc_t acpPollCreate(acp_poll_set_t *aPollSet, acp_sint32_t aMaxCount) { acp_rc_t sRC; ACP_POLL_CHECK_BEFORE_CREATE(aPollSet, aMaxCount); /* Create port */ aPollSet->mHandle = port_create(); if (aPollSet->mHandle == -1) { return ACP_RC_GET_NET_ERROR(); } else { /* do nothing */ } sRC = acpMemCalloc((void **)&aPollSet->mObjs, aMaxCount, sizeof(acp_poll_obj_t)); if (ACP_RC_NOT_SUCCESS(sRC)) { (void)close(aPollSet->mHandle); return sRC; } else { /* do nothing */ } sRC = acpMemCalloc((void **)&aPollSet->mEvents, aMaxCount, sizeof(port_event_t)); if (ACP_RC_NOT_SUCCESS(sRC)) { (void)close(aPollSet->mHandle); acpMemFree(aPollSet->mObjs); return sRC; } else { /* do nothing */ } aPollSet->mMaxCount = aMaxCount; aPollSet->mCurCount = 0; aPollSet->mEventHandle = -1; aPollSet->mEventsNum = 0; aPollSet->mCurrEvent = 0; return ACP_RC_SUCCESS; }
static void *eventer_ports_spec_alloc(void) { struct ports_spec *spec; spec = calloc(1, sizeof(*spec)); spec->port_fd = port_create(); if(spec->port_fd < 0) { mtevFatal(mtev_error, "error in eveter_ports_spec_alloc... spec->port_fd < 0 (%d)\n", spec->port_fd); } return spec; }
int uv__platform_loop_init(uv_loop_t* loop, int default_loop) { loop->fs_fd = -1; loop->backend_fd = port_create(); if (loop->backend_fd == -1) return -1; uv__cloexec(loop->backend_fd, 1); return 0; }
port_id user_port_create(int32 queue_length, const char *uname) { dprintf("user_port_create: queue_length %d\n", queue_length); if(uname != NULL) { char name[SYS_MAX_OS_NAME_LEN]; int rc; if(is_kernel_address(uname)) return ERR_VM_BAD_USER_MEMORY; rc = user_strncpy(name, uname, SYS_MAX_OS_NAME_LEN-1); if(rc < 0) return rc; name[SYS_MAX_OS_NAME_LEN-1] = 0; return port_create(queue_length, name); } else { return port_create(queue_length, NULL); } }
int event_queue_init() { int port = port_create(); if (port < 0) { uwsgi_error("port_create()"); return -1; } return port; }
/* * init_netio * * This is a needed exported function which will be called to initialise * the network loop code. */ void init_netio(void) { if((pe = port_create()) < 0) { libcharybdis_log("init_netio: Couldn't open port fd!\n"); exit(115); /* Whee! */ } pemax = getdtablesize(); pelst = MyMalloc(sizeof(port_event_t) * pemax); zero_timespec.tv_sec = 0; zero_timespec.tv_nsec = 0; }
ret_t fdpoll_port_new (cherokee_fdpoll_t **fdp, int sys_limit, int limit) { cuint_t i; cherokee_fdpoll_t *nfd; CHEROKEE_CNEW_STRUCT (1, n, fdpoll_port); nfd = FDPOLL(n); /* Init base class properties */ nfd->type = cherokee_poll_port; nfd->nfiles = limit; nfd->system_nfiles = sys_limit; nfd->npollfds = 0; /* Init base class virtual methods */ nfd->free = (fdpoll_func_free_t) _free; nfd->add = (fdpoll_func_add_t) _add; nfd->del = (fdpoll_func_del_t) _del; nfd->reset = (fdpoll_func_reset_t) _reset; nfd->set_mode = (fdpoll_func_set_mode_t) _set_mode; nfd->check = (fdpoll_func_check_t) _check; nfd->watch = (fdpoll_func_watch_t) _watch; /* Allocate data */ n->port = -1; n->port_readyfds = 0; n->port_events = (port_event_t *) calloc(nfd->nfiles, sizeof(port_event_t)); n->port_activefd = (int *) calloc(nfd->system_nfiles, sizeof(int)); if ( n->port_events == NULL || n->port_activefd == NULL ) { _free( n ); return ret_nomem; } for (i=0; i < nfd->system_nfiles; i++) { n->port_activefd[i] = -1; } if ( (n->port = port_create()) == -1 ) { _free( n ); return ret_error; } /* Return the object */ *fdp = nfd; return ret_ok; }
static apr_status_t impl_pollset_create(apr_pollset_t *pollset, apr_uint32_t size, apr_pool_t *p, apr_uint32_t flags) { apr_status_t rv = APR_SUCCESS; pollset->p = apr_palloc(p, sizeof(apr_pollset_private_t)); #if APR_HAS_THREADS if (flags & APR_POLLSET_THREADSAFE && ((rv = apr_thread_mutex_create(&pollset->p->ring_lock, APR_THREAD_MUTEX_DEFAULT, p)) != APR_SUCCESS)) { pollset->p = NULL; return rv; } #else if (flags & APR_POLLSET_THREADSAFE) { pollset->p = NULL; return APR_ENOTIMPL; } #endif pollset->p->waiting = 0; pollset->p->port_set = apr_palloc(p, size * sizeof(port_event_t)); pollset->p->port_fd = port_create(); if (pollset->p->port_fd < 0) { pollset->p = NULL; return apr_get_netos_error(); } { int flags; if ((flags = fcntl(pollset->p->port_fd, F_GETFD)) == -1) return errno; flags |= FD_CLOEXEC; if (fcntl(pollset->p->port_fd, F_SETFD, flags) == -1) return errno; } pollset->p->result_set = apr_palloc(p, size * sizeof(apr_pollfd_t)); APR_RING_INIT(&pollset->p->query_ring, pfd_elem_t, link); APR_RING_INIT(&pollset->p->add_ring, pfd_elem_t, link); APR_RING_INIT(&pollset->p->free_ring, pfd_elem_t, link); APR_RING_INIT(&pollset->p->dead_ring, pfd_elem_t, link); return rv; }
int main(int argc, char * const argv[]) { int c; boolean_t fork = B_TRUE; progname = basename(strdup(argv[0])); if ((fmri = (const char *)getenv("SMF_FMRI")) == NULL) fmri = DEFAULT_FMRI; (void) setlocale(LC_ALL, ""); #if !defined(TEXT_DOMAIN) #define TEXT_DOMAIN "SYS_TEST" #endif (void) textdomain(TEXT_DOMAIN); while ((c = getopt(argc, argv, "djn")) != EOF) { switch (c) { case 'd': dlevel = 0xffff; break; case 'j': json = B_TRUE; break; case 'n': fork = B_FALSE; break; default: (void) fprintf(stderr, gettext("Unknown option " "\'%c\'.\n"), c); usage(progname); } } pid = getpid(); if ((main_port = port_create()) == -1) err(EXIT_FAILURE, "port_create() failed"); list_create(&links, sizeof (link_t), offsetof(link_t, node)); VERIFY(get_sysinfo()); lldp_read_config(); signal_init(); get_port_list(); lldp_init(4); cdp_init(4); main_loop(); return (0); }
void inline_size port_fork (EV_P) { close (backend_fd); while ((backend_fd = port_create ()) < 0) ev_syserr ("(libev) port"); fcntl (backend_fd, F_SETFD, FD_CLOEXEC); /* re-register interest in fds */ fd_rearm_all (EV_A); }
vws_init(struct waiter *w) { struct vws *vws; CHECK_OBJ_NOTNULL(w, WAITER_MAGIC); vws = w->priv; INIT_OBJ(vws, VWS_MAGIC); vws->waiter = w; vws->dport = port_create(); assert(vws->dport >= 0); AZ(pthread_create(&vws->thread, NULL, vws_thread, vws)); }
int console_main(void) { int err,i; area_create(0x2000, 0, &screen, AREA_PHYSMAP); console_port = port_create(0,"console_listen_port"); send_port = port_create(0,"console_send_port"); port_option(send_port, PORT_OPT_NOWAIT, 1); err = namer_register(console_port,"console"); init_virtscreen(&statbar, 1, 80); statbar.back = statbar.data; statbar.data = (unsigned short *) (((uint32) screen) + 80*24*2); statbar.lock = sem_create(1,"statbar_lock"); for(i=0;i<10;i++){ init_virtscreen(&con[i], 24, 80); con[i].back = con[i].data; con[i].lock = sem_create(1,"vscr_lock"); vputs(&con[i],CLEAR); } load(&con[0]); status(0); if(err) vprintf(active,"console: the namer hates us\n"); else #ifdef CONSOLE_DEBUG vprintf(active,"console: " FG_GREEN "online." FG_WHITE "\n"); #else ; #endif thr_create(keyboard_irq_thread, NULL, "console:kbd"); ready = 1; console_thread(); return 0; }
int rb_init_netio_ports(void) { if((pe = port_create()) < 0) { return errno; } pemax = getdtablesize(); pelst = rb_malloc(sizeof(port_event_t) * pemax); zero_timespec.tv_sec = 0; zero_timespec.tv_nsec = 0; rb_set_time(); return 0; }
mowgli_ioevent_handle_t *mowgli_ioevent_create(void) { mowgli_ioevent_handle_t *self = mowgli_alloc(sizeof(mowgli_ioevent_handle_t)); #ifdef HAVE_EPOLL_CTL self->impldata = epoll_create(FD_SETSIZE); #endif #ifdef HAVE_PORT_CREATE self->impldata = port_create(); #endif return self; }