/** * Callback invoked by curl to poll reading / writing of a socket. */ static int curlSocketCallback(CURL *easy, curl_socket_t s, int action, void *userp, void *socketp) { struct ReadWriteSockets* sockets = userp; (void)easy; /* unused */ (void)socketp; /* unused */ if (action == CURL_POLL_IN || action == CURL_POLL_INOUT) addFd(&sockets->read, s, "read"); if (action == CURL_POLL_OUT || action == CURL_POLL_INOUT) addFd(&sockets->write, s, "write"); if(action == CURL_POLL_REMOVE) { removeFd(&sockets->read, s, 1); removeFd(&sockets->write, s, 0); } return 0; }
int PortalPoller::registerInstance(Portal *portal) { uint8_t ch = 0; pthread_mutex_lock(&mutex); int rc = write(pipefd[1], &ch, 1); // get poll to return, so that it is no long using portal_fds (which gets realloc'ed) if (rc < 0) fprintf(stderr, "[%s:%d] write error %d\n", __FUNCTION__, __LINE__, errno); numWrappers++; fprintf(stderr, "Portal::registerInstance fpga%d fd %d clients %d\n", portal->pint.fpga_number, portal->pint.fpga_fd, portal->pint.client_fd_number); portal_wrappers = (Portal **)realloc(portal_wrappers, numWrappers*sizeof(Portal *)); portal_wrappers[numWrappers-1] = portal; if (portal->pint.fpga_fd != -1) addFd(portal->pint.fpga_fd); for (int i = 0; i < portal->pint.client_fd_number; i++) addFd(portal->pint.client_fd[i]); portal->pint.item->enableint(&portal->pint, 1); pthread_mutex_unlock(&mutex); start(); return 0; }
void* PortalPoller::init(void) { #ifdef BSIM if (global_sockfd != -1) { pthread_mutex_lock(&mutex); addFd(global_sockfd); pthread_mutex_unlock(&mutex); } #endif fprintf(stderr, "portalExec::about to enter loop, numFds=%d\n", numFds); return NULL; }
PortalPoller::PortalPoller() : portal_wrappers(0), portal_fds(0), startThread(1), numWrappers(0), numFds(0), stopping(0) { int rc = pipe(pipefd); if (rc != 0) fprintf(stderr, "[%s:%d] pipe error %d:%s\n", __FUNCTION__, __LINE__, errno, strerror(errno)); sem_init(&sem_startup, 0, 0); pthread_mutex_init(&mutex, NULL); fcntl(pipefd[0], F_SETFL, O_NONBLOCK); addFd(pipefd[0]); timeout = -1; #if defined(BSIM) || defined(BOARD_xsim) timeout = 100; #endif }
/* Open a file (restarting after signal interrupt if necessary) Returns shared pointer to file object or NULL on error */ File::FilePtr FileManager::openFileObj(const std::string& fileName, int flags) { int fd = -1; File::FilePtr ret; /* Try to open the file */ fd = File::openFile(fileName, flags); /* Create the file object and put it on the lru */ if (fd >= 0) { flags = flags & (~O_CREAT) & (~O_EXCL) & (~O_TRUNC); ret.reset(new File(fd, fileName, flags, false)); addFd(*ret); } return ret; }
/* Create a (temp) file object (file is removed on close) if filePath is specified, use it for the path of the file */ File::FilePtr FileManager::createTemporary(std::string const& arrName, char const* filePath) { std::string dir; int fd; /* Try to create the temp file */ if (filePath == NULL) { #ifndef SCIDB_CLIENT dir = Config::getInstance()->getOption<std::string>(CONFIG_TMP_PATH); #endif if (dir.length() != 0 && dir[dir.length()-1] != '/') { dir += '/'; } dir += arrName; dir += ".XXXXXX"; filePath = dir.c_str(); fd = ::mkstemp((char*)filePath); } else { fd = ::open(filePath, O_RDWR|O_TRUNC|O_EXCL|O_CREAT|O_LARGEFILE, 0666); } if (fd < 0) { // For certain types of transient errors, we can throw a USER EXCEPTION if (errno == EMFILE) { throw USER_EXCEPTION(SCIDB_SE_INTERNAL, SCIDB_LE_TOO_MANY_OPEN_FILES); } throw SYSTEM_EXCEPTION(SCIDB_SE_INTERNAL, SCIDB_LE_CANT_OPEN_FILE) << filePath << errno; } /* Create the file object and put it on the lru */ File::FilePtr ret(new File(fd, filePath, O_RDWR|O_LARGEFILE, true)); addFd(*ret); return ret; }
int Poll::addFd(int fd, int ident, int events, ALooper_callbackFunc callback, void* data) { return addFd(fd, ident, events, callback ? new SimplePollerCallback(callback) : NULL, data); }