CRYSTAX_LOCAL int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen) { DBG("sockfd=%d, addrlen=%lu", sockfd, (unsigned long)addrlen); int extfd; if (!resolve(sockfd, NULL, &extfd, NULL, NULL)) return -1; if (extfd == -1) { errno = EBADF; return -1; } int extconnfd = system_connect(extfd, addr, addrlen); if (extconnfd == -1) return -1; int connfd = alloc_fd(NULL, extconnfd, system::driver_t::instance()); if (connfd < 0) { system_close(extconnfd); errno = EMFILE; return -1; } DBG("return fd=%d", connfd); return connfd; }
int MiniGUIMain (int args, const char* arg[]) { HWND hMainWnd; MSG Msg; MAINWINCREATE CreateInfo; DoSysCmd("date >> CurrentVer"); DoSysCmd("echo \""PROVER"\" >> CurrentVer"); init(); InitCreateInfo (&CreateInfo); hMainWnd = CreateMainWindow (&CreateInfo); if (hMainWnd == HWND_INVALID) return -1; ShowWindow (hMainWnd, SW_SHOWNORMAL); SetCursorPos (805, 605) ; while ( GetMessage (&Msg, hMainWnd) ) { TranslateMessage (&Msg); DispatchMessage (&Msg); } I_DEV_IOBoard_Exit(); MainWindowThreadCleanup (hMainWnd); system_close(); exit(0); return 0; }
static int menuSetFinishPro( uint16_t value, uint8_t *p_GetParam )// reboot the program { //sync();// 同步所有文件 DEBUG_INFO( "System Close......" ); #if 0 system_close( &threads ); #else lcd192x64_close();// yasirLiang add in 2016/05/16 #endif DEBUG_INFO( "System Close Success!" ); system("reboot"); //exit(0); return 0; }
int dc_close2(int fd) { int res = 0; struct vsp_node *node; int32_t size; #ifdef DC_CALL_TRACE showTraceBack(); #endif /* nothing wrong ... yet */ dc_errno = DEOK; node = delete_vsp_node(fd); if (node == NULL) { /* we have not such file descriptor, so lets give a try to system */ return system_close(fd); } dc_real_fsync( node ); if(node->unsafeWrite) { size = htonl(-1); /* send end of data */ writen(node->dataFd, (char *) &size, sizeof(size), NULL); /* FIXME: error detection missing */ if (get_fin(node) < 0) { dc_debug(DC_ERROR, "dc_close: mover did not FIN the data blocks."); res = -1; } } close_data_socket(node->dataFd); deleteQueue(node->queueID); m_unlock(&node->mux); node_destroy(node); return res; }
/** * Connects to specified host and service. The service can be service name as * defined in /etc/services or port number in string form. * * returns non negative socket descriptor or -1 on error. */ int socket_connect(const char *host, const char *service) { int fd = -1; struct addrinfo hints, *res_addrinfo, *ai; int rc; #ifdef WIN32 initWinSock(); #endif /* WIN32 */ memset(&hints, 0, sizeof (hints)); hints.ai_family = AF_UNSPEC; /* IPv6 + IPv4 */ hints.ai_socktype = SOCK_STREAM; /* TCP */ rc = getaddrinfo(host, service, &hints, &res_addrinfo); if (rc) { dc_errno = DESOCKET; return -1; } for (ai = res_addrinfo; ai != NULL; ai = ai->ai_next) { fd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); if (fd < 0) continue; if (nio_connect(fd, ai->ai_addr, ai->ai_addrlen, 20) == 0) break; system_close(fd); fd = -1; } freeaddrinfo(res_addrinfo); if (fd < 0) { dc_errno = DECONNECT; } return fd; }
gint intercept_close(gint fd) { return system_close(fd); }
int dc_close(int fd) { int res = 0; int tmp; int32_t size; int32_t closemsg[6]; int msglen; struct vsp_node *node; #ifdef DC_CALL_TRACE showTraceBack(); #endif /* nothing wrong ... yet */ dc_errno = DEOK; node = delete_vsp_node(fd); if (node == NULL) { /* we have not such file descriptor, so lets give a try to system */ dc_debug(DC_INFO, "Using system native close for [%d].", fd); return system_close(fd); } if ( node->lcb != NULL ) { dc_lcb_clean( node ); } dc_real_fsync( node ); if(node->unsafeWrite > 1) { size = htonl(-1); /* send end of data */ writen(node->dataFd, (char *) &size, sizeof(size), NULL); /* FIXME: error detection missing */ if (get_fin(node) < 0) { dc_debug(DC_ERROR, "dc_close: mover did not FIN the data blocks."); res = -1; } } if(node->reference == 0 ) { if( (node->sum != NULL) && ( node->sum->isOk == 1 ) ) { closemsg[0] = htonl(20); closemsg[2] = htonl(12); closemsg[3] = htonl(DCAP_DATA_SUM); closemsg[4] = htonl(node->sum->type); closemsg[5] = htonl(node->sum->sum); msglen = 6; dc_debug(DC_INFO, "File checksum is: %u", node->sum->sum); }else{ closemsg[0] = htonl(4); msglen = 2; } closemsg[1] = htonl(IOCMD_CLOSE); /* actual command */ dc_debug(DC_IO, "Sending CLOSE for fd:%d ID:%d.", node->dataFd, node->queueID); check_timeout_envar(); dcap_set_alarm(closeTimeOut > 0 ? closeTimeOut : DCAP_IO_TIMEOUT/4); tmp = sendDataMessage(node, (char *) closemsg, msglen*sizeof(int32_t), ASCII_OK, NULL); /* FIXME: error detection missing */ if( tmp < 0 ) { dc_debug(DC_ERROR, "sendDataMessage failed."); /* ignore close errors if file was open for read */ if(node->flags & O_WRONLY) { res = -1; } if(isIOFailed) { isIOFailed = 0; /* command line dwon */ if(!ping_pong(node)) { /* remove file descriptor from the list of control lines in use */ lockMember(); deleteMemberByValue(node->fd); unlockMember(); pollDelete(node->fd); close_control_socket(node->fd, node->tunnel); } } } dcap_set_alarm(0); deleteQueue(node->queueID); } /* * Even if there is still a reference to the dcap session, * we have to close local socket descriptor. */ close_data_socket(node->dataFd); node_destroy(node); return res; }