/* See Porting Layer Definition - p. 17 */ void InitInput (int argc, char *argv[]) { DeviceIntPtr pMouse, pKeyboard; #if CYGDEBUG winDebug ("InitInput\n"); #endif #ifdef XWIN_CLIPBOARD /* * Wrap some functions at every generation of the server. */ if (InitialVector[2] != winProcEstablishConnection) { winProcEstablishConnectionOrig = InitialVector[2]; InitialVector[2] = winProcEstablishConnection; } if (g_fXdmcpEnabled && ProcVector[X_QueryTree] != winProcQueryTree) { winProcQueryTreeOrig = ProcVector[X_QueryTree]; ProcVector[X_QueryTree] = winProcQueryTree; } #endif pMouse = AddInputDevice (winMouseProc, TRUE); pKeyboard = AddInputDevice (winKeybdProc, TRUE); RegisterPointerDevice (pMouse); RegisterKeyboardDevice (pKeyboard); miRegisterPointerDevice (screenInfo.screens[0], pMouse); mieqInit ((DevicePtr)pKeyboard, (DevicePtr)pMouse); /* Initialize the mode key states */ winInitializeModeKeyStates (); #ifdef HAS_DEVWINDOWS /* Only open the windows message queue device once */ if (g_fdMessageQueue == WIN_FD_INVALID) { /* Open a file descriptor for the Windows message queue */ g_fdMessageQueue = open (WIN_MSG_QUEUE_FNAME, O_RDONLY); if (g_fdMessageQueue == -1) { FatalError ("InitInput - Failed opening %s\n", WIN_MSG_QUEUE_FNAME); } /* Add the message queue as a device to wait for in WaitForSomething */ AddEnabledDevice (g_fdMessageQueue); } #endif #if CYGDEBUG winDebug ("InitInput - returning\n"); #endif }
/* * xf86AddEnabledDevice -- * */ void xf86AddEnabledDevice(InputInfoPtr pInfo) { if (!xf86InstallSIGIOHandler (pInfo->fd, xf86SigioReadInput, pInfo)) { AddEnabledDevice(pInfo->fd); } }
int rfbConnect(char *host, int port) { int sock; int one = 1; fprintf(stderr, "\n"); rfbLog("Making connection to client on host %s port %d\n", host, port); if ((sock = ConnectToTcpAddr(host, port)) < 0) { rfbLogPerror("connection failed"); return -1; } if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) { rfbLogPerror("fcntl failed"); close(sock); return -1; } if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *)&one, sizeof(one)) < 0) { rfbLogPerror("setsockopt failed"); close(sock); return -1; } AddEnabledDevice(sock); FD_SET(sock, &allFds); maxFd = max(sock, maxFd); return sock; }
void httpInitSockets() { static Bool done = FALSE; if (done) return; done = TRUE; if (!httpDir) return; if (httpPort == 0) { httpPort = 5800 + atoi(display); } rfbLog("Listening for HTTP connections on TCP port %d\n", httpPort); rfbLog(" URL http://%s:%d\n",rfbThisHost,httpPort); if ((httpListenSock = ListenOnTCPPort(httpPort)) < 0) { rfbLogPerror("ListenOnTCPPort"); exit(1); } AddEnabledDevice(httpListenSock); }
pointer xf86AddInputHandler(int fd, InputHandlerProc proc, pointer data) { IHPtr ih = addInputHandler(fd, proc, data); if (ih) AddEnabledDevice(fd); return ih; }
void xf86EnableInputHandler(pointer handler) { IHPtr ih; if (!handler) return; ih = handler; ih->enabled = TRUE; if (ih->fd >= 0) AddEnabledDevice(ih->fd); }
void LinuxApmOpen(void) { LinuxApmFd = open ("/dev/apm_bios", 2); if (LinuxApmFd < 0 && errno == ENOENT) LinuxApmFd = open ("/dev/misc/apm_bios", 2); if (LinuxApmFd >= 0) { LinuxApmRunning = TRUE; fcntl (LinuxApmFd, F_SETFL, fcntl (LinuxApmFd, F_GETFL) | NOBLOCK); RegisterBlockAndWakeupHandlers (LinuxApmBlock, LinuxApmWakeup, 0); AddEnabledDevice (LinuxApmFd); } }
static void LinuxEnable (void) { if (enabled) return; if (kdSwitchPending) { kdSwitchPending = FALSE; ioctl (LinuxConsoleFd, VT_RELDISP, VT_ACKACQ); } /* * Open the APM driver */ LinuxApmFd = open ("/dev/apm_bios", 2); if (LinuxApmFd < 0 && errno == ENOENT) LinuxApmFd = open ("/dev/misc/apm_bios", 2); if (LinuxApmFd >= 0) { LinuxApmRunning = TRUE; fcntl (LinuxApmFd, F_SETFL, fcntl (LinuxApmFd, F_GETFL) | NOBLOCK); RegisterBlockAndWakeupHandlers (LinuxApmBlock, LinuxApmWakeup, 0); AddEnabledDevice (LinuxApmFd); } /* * now get the VT */ LinuxSetSwitchMode (VT_AUTO); if (ioctl(LinuxConsoleFd, VT_ACTIVATE, vtno) != 0) { FatalError("LinuxInit: VT_ACTIVATE failed\n"); } if (ioctl(LinuxConsoleFd, VT_WAITACTIVE, vtno) != 0) { FatalError("LinuxInit: VT_WAITACTIVE failed\n"); } LinuxSetSwitchMode (VT_PROCESS); if (ioctl(LinuxConsoleFd, KDSETMODE, KD_GRAPHICS) < 0) { FatalError("LinuxInit: KDSETMODE KD_GRAPHICS failed\n"); } enabled = TRUE; }
void InitInput(int argc, char *argv[]) { int rc; rc = AllocDevicePair(serverClient, "Xnest", &xnestPointerDevice, &xnestKeyboardDevice, xnestPointerProc, xnestKeyboardProc, FALSE); if (rc != Success) FatalError("Failed to init Xnest default devices.\n"); mieqInit(); AddEnabledDevice(XConnectionNumber(xnestDisplay)); RegisterBlockAndWakeupHandlers(xnestBlockHandler, xnestWakeupHandler, NULL); }
static void KdAddFd (int fd) { struct sigaction act; sigset_t set; kdnFds++; fcntl (fd, F_SETOWN, getpid()); KdNonBlockFd (fd); AddEnabledDevice (fd); memset (&act, '\0', sizeof act); act.sa_handler = KdSigio; sigemptyset (&act.sa_mask); sigaddset (&act.sa_mask, SIGIO); sigaddset (&act.sa_mask, SIGALRM); sigaddset (&act.sa_mask, SIGVTALRM); sigaction (SIGIO, &act, 0); sigemptyset (&set); sigprocmask (SIG_SETMASK, &set, 0); }
void InitInput(int argc, char *argv[]) { xnestPointerDevice = AddInputDevice(xnestPointerProc, TRUE); xnestKeyboardDevice = AddInputDevice(xnestKeyboardProc, TRUE); if (!xnestEvents) xnestEvents = (xEvent *) xcalloc(sizeof(xEvent), GetMaximumEventsNum()); if (!xnestEvents) FatalError("couldn't allocate room for events\n"); RegisterPointerDevice(xnestPointerDevice); RegisterKeyboardDevice(xnestKeyboardDevice); mieqInit(); AddEnabledDevice(XConnectionNumber(xnestDisplay)); RegisterBlockAndWakeupHandlers(xnestBlockHandler, xnestWakeupHandler, NULL); }
/* See Porting Layer Definition - p. 17 */ void InitInput (int argc, char *argv[]) { DeviceIntPtr pMouse, pKeyboard; #if CYGDEBUG ErrorF ("InitInput\n"); #endif pMouse = AddInputDevice (winMouseProc, TRUE); pKeyboard = AddInputDevice (winKeybdProc, TRUE); RegisterPointerDevice (pMouse); RegisterKeyboardDevice (pKeyboard); miRegisterPointerDevice (screenInfo.screens[0], pMouse); mieqInit ((DevicePtr)pKeyboard, (DevicePtr)pMouse); /* Initialize the mode key states */ winInitializeModeKeyStates (); /* Only open the windows message queue device once */ if (g_fdMessageQueue == WIN_FD_INVALID) { /* Open a file descriptor for the Windows message queue */ g_fdMessageQueue = open (WIN_MSG_QUEUE_FNAME, O_RDONLY); if (g_fdMessageQueue == -1) { FatalError ("InitInput - Failed opening %s\n", WIN_MSG_QUEUE_FNAME); } /* Add the message queue as a device to wait for in WaitForSomething */ AddEnabledDevice (g_fdMessageQueue); } #if CYGDEBUG ErrorF ("InitInput - returning\n"); #endif }
void rfbCheckFds() { int nfds; fd_set fds; struct timeval tv; struct sockaddr_storage addr; socklen_t addrlen = sizeof(addr); char addrStr[INET6_ADDRSTRLEN]; char buf[6]; const int one = 1; int sock; rfbClientPtr cl; static Bool inetdInitDone = FALSE; if (!inetdInitDone && inetdSock != -1) { rfbNewClientConnection(inetdSock); inetdInitDone = TRUE; } memcpy((char *)&fds, (char *)&allFds, sizeof(fd_set)); tv.tv_sec = 0; tv.tv_usec = 0; nfds = select(maxFd + 1, &fds, NULL, NULL, &tv); if (nfds == 0) { return; } if (nfds < 0) { rfbLogPerror("rfbCheckFds: select"); return; } if (rfbListenSock != -1 && FD_ISSET(rfbListenSock, &fds)) { if ((sock = accept(rfbListenSock, (struct sockaddr *)&addr, &addrlen)) < 0) { rfbLogPerror("rfbCheckFds: accept"); return; } if (fcntl(sock, F_SETFL, O_NONBLOCK) < 0) { rfbLogPerror("rfbCheckFds: fcntl"); close(sock); return; } if (setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (char *)&one, sizeof(one)) < 0) { rfbLogPerror("rfbCheckFds: setsockopt"); close(sock); return; } fprintf(stderr, "\n"); #if USE_LIBWRAP if (!hosts_ctl("Xvnc", STRING_UNKNOWN, sockaddr_string(&addr, addrStr, INET6_ADDRSTRLEN), STRING_UNKNOWN)) { rfbLog("Rejected connection from client %s\n", sockaddr_string(&addr, addrStr, INET6_ADDRSTRLEN)) close(sock); return; } #endif rfbLog("Got connection from client %s\n", sockaddr_string(&addr, addrStr, INET6_ADDRSTRLEN)); AddEnabledDevice(sock); FD_SET(sock, &allFds); maxFd = max(sock, maxFd); rfbNewClientConnection(sock); FD_CLR(rfbListenSock, &fds); if (--nfds == 0) return; } if ((udpSock != -1) && FD_ISSET(udpSock, &fds)) { if (recvfrom(udpSock, buf, 1, MSG_PEEK, (struct sockaddr *)&addr, &addrlen) < 0) { rfbLogPerror("rfbCheckFds: UDP: recvfrom"); rfbDisconnectUDPSock(); } else { if (!udpSockConnected || (memcmp(&addr, &udpRemoteAddr, addrlen) != 0)) { /* new remote end */ rfbLog("rfbCheckFds: UDP: got connection\n"); memcpy(&udpRemoteAddr, &addr, addrlen); udpSockConnected = TRUE; if (connect(udpSock, (struct sockaddr *)&addr, addrlen) < 0) { rfbLogPerror("rfbCheckFds: UDP: connect"); rfbDisconnectUDPSock(); return; } rfbNewUDPConnection(udpSock); } rfbProcessUDPInput(udpSock); } FD_CLR(udpSock, &fds); if (--nfds == 0) return; } for (cl = rfbClientHead; cl; cl = cl->next) { if (FD_ISSET(cl->sock, &fds) && FD_ISSET(cl->sock, &allFds)) { rfbClientPtr cl2; #if USETLS do { rfbProcessClientMessage(cl); /* Make sure cl hasn't been freed */ for (cl2 = rfbClientHead; cl2; cl2 = cl2->next) { if (cl2 == cl) break; } if (cl2 == NULL) return; } while (cl->sslctx && rfbssl_pending(cl) > 0); #else rfbProcessClientMessage(cl); for (cl2 = rfbClientHead; cl2; cl2 = cl2->next) { if (cl2 == cl) break; } if (cl2 == NULL) return; #endif } } }
void rfbInitSockets() { static Bool done = FALSE; if (done) return; done = TRUE; if (inetdSock != -1) { const int one = 1; if (fcntl(inetdSock, F_SETFL, O_NONBLOCK) < 0) { rfbLogPerror("fcntl"); exit(1); } if (setsockopt(inetdSock, IPPROTO_TCP, TCP_NODELAY, (char *)&one, sizeof(one)) < 0) { rfbLogPerror("setsockopt"); exit(1); } AddEnabledDevice(inetdSock); FD_ZERO(&allFds); FD_SET(inetdSock, &allFds); maxFd = inetdSock; return; } if (rfbPort == 0) { rfbPort = 5900 + atoi(display); } rfbLog("Listening for VNC connections on TCP port %d\n", rfbPort); if ((rfbListenSock = ListenOnTCPPort(rfbPort)) < 0) { rfbLogPerror("ListenOnTCPPort"); exit(1); } AddEnabledDevice(rfbListenSock); FD_ZERO(&allFds); FD_SET(rfbListenSock, &allFds); maxFd = rfbListenSock; if (udpPort != 0) { rfbLog("rfbInitSockets: listening for input on UDP port %d\n", udpPort); if ((udpSock = ListenOnUDPPort(udpPort)) < 0) { rfbLogPerror("ListenOnUDPPort"); exit(1); } AddEnabledDevice(udpSock); FD_SET(udpSock, &allFds); maxFd = max(udpSock, maxFd); } }
void httpCheckFds() { int nfds, n; fd_set fds; struct timeval tv; struct sockaddr_in addr; int addrlen = sizeof(addr); if (!httpDir) return; FD_ZERO(&fds); FD_SET(httpListenSock, &fds); if (httpSock >= 0) { FD_SET(httpSock, &fds); } tv.tv_sec = 0; tv.tv_usec = 0; nfds = select(max(httpSock,httpListenSock) + 1, &fds, NULL, NULL, &tv); if (nfds == 0) { return; } if (nfds < 0) { rfbLogPerror("httpCheckFds: select"); return; } if ((httpSock >= 0) && FD_ISSET(httpSock, &fds)) { httpProcessInput(); } if (FD_ISSET(httpListenSock, &fds)) { int flags; if (httpSock >= 0) close(httpSock); if ((httpSock = accept(httpListenSock, (struct sockaddr *)&addr, &addrlen)) < 0) { rfbLogPerror("httpCheckFds: accept"); return; } #if USE_LIBWRAP if (!hosts_ctl("Xvnc", STRING_UNKNOWN, inet_ntoa(addr.sin_addr), STRING_UNKNOWN)) { rfbLog("Rejected HTTP connection from client %s\n", inet_ntoa(addr.sin_addr)); close(httpSock); httpSock = -1; return; } #endif flags = fcntl (httpSock, F_GETFL); if (flags == -1 || fcntl (httpSock, F_SETFL, flags | O_NONBLOCK) == -1) { rfbLogPerror("httpCheckFds: fcntl"); close (httpSock); httpSock = -1; return; } AddEnabledDevice(httpSock); } }
/* See Porting Layer Definition - p. 17 */ void InitInput (int argc, char *argv[]) { DeviceIntPtr pMouse, pKeyboard; #if CYGDEBUG ErrorF ("InitInput\n"); #endif pMouse = AddInputDevice (winMouseProc, TRUE); pKeyboard = AddInputDevice (winKeybdProc, TRUE); RegisterPointerDevice (pMouse); RegisterKeyboardDevice (pKeyboard); miRegisterPointerDevice (screenInfo.screens[0], pMouse); mieqInit ((DevicePtr)pKeyboard, (DevicePtr)pMouse); /* Initialize the mode key states */ winInitializeModeKeyStates (); /* Only open the windows message queue device once */ if (g_fdMessageQueue == WIN_FD_INVALID) { /* Open a file descriptor for the Windows message queue */ g_fdMessageQueue = open (WIN_MSG_QUEUE_FNAME, O_RDONLY); if (g_fdMessageQueue == -1) { FatalError ("InitInput - Failed opening %s\n", WIN_MSG_QUEUE_FNAME); } /* Add the message queue as a device to wait for in WaitForSomething */ AddEnabledDevice (g_fdMessageQueue); } #if 0 { MiscExtReturn ret; pointer kbd; #if 0 if ((kbd = MiscExtCreateStruct(MISC_KEYBOARD)) == (pointer) 0) return BadAlloc; #else kbd = MiscExtCreateStruct (MISC_KEYBOARD); #endif MiscExtSetKbdValue(kbd, MISC_KBD_TYPE, 0); MiscExtSetKbdValue(kbd, MISC_KBD_RATE, 0); MiscExtSetKbdValue(kbd, MISC_KBD_DELAY, 0); MiscExtSetKbdValue(kbd, MISC_KBD_SERVNUMLOCK, 0); switch ((ret = MiscExtApply (kbd, MISC_KEYBOARD))) { case MISC_RET_SUCCESS: break; case MISC_RET_BADVAL: case MISC_RET_BADKBDTYPE: default: ErrorF ("Unexpected return from MiscExtApply(KEYBOARD) = %d\n", ret); } } #endif #if CYGDEBUG ErrorF ("InitInput - returning\n"); #endif }