static void posix_ttyname (void) { SLFile_FD_Type *f; SLang_MMT_Type *mmt; int fd; char buf[512]; int e; if (SLang_Num_Function_Args == 0) { fd = 0; f = NULL; mmt = NULL; } else if (-1 == pop_fd (&fd, &f, &mmt)) return; if (0 != (e = TTYNAME_R (fd, buf, sizeof(buf)))) { _pSLerrno_errno = e; SLang_push_null (); } else (void) SLang_push_string (buf); if (mmt != NULL) SLang_free_mmt (mmt); if (f != NULL) SLfile_free_fd (f); }
static int fcntl_setfd (int *flags) { int fd; if (-1 == pop_fd (&fd)) return -1; return do_fcntl_3_int (fd, F_SETFD, *flags); }
static int fcntl_getfl (void) { int fd; if (-1 == pop_fd (&fd)) return -1; return do_fcntl_2 (fd, F_GETFL); }
static int my_exit(t_fd *fds, int ret) { t_fd *ptr; t_fd *tmp; ptr = fds; while (ptr) { tmp = ptr; ptr = ptr->next; pop_fd(&fds, tmp); free(tmp); } return (ret); }
static int posix_isatty (void) { int ret; SLFile_FD_Type *f; SLang_MMT_Type *mmt; int fd; if (-1 == pop_fd (&fd, &f, &mmt)) return 0; /* invalid descriptor */ if (0 == (ret = isatty (fd))) _pSLerrno_errno = errno; if (mmt != NULL) SLang_free_mmt (mmt); if (f != NULL) SLfile_free_fd (f); return ret; }
void __cdecl output_and_cleanup(int code) { FILE *f; string line; if (code == 0) { /* output result if any */ if ((f = fopen(getval("STDOUT"), "r")) != NULL) { if (redirect_stdout >= 0) { int fds[3]; fds[0] = 0; fds[1] = redirect_stdout; fds[2] = 2; push_fd(fds); } while((line = read_line(f)) != NULL) { fputs(line, stdout); free (line); } fclose(f); if (redirect_stdout >= 0) { pop_fd(); redirect_stdout = -1; } } } if (test_file('d', tmpdir)) rec_rmdir(tmpdir); { int count = 0; /* Give more than one chance to remove the files */ while ((count++ < 20) && test_file('d', tmpdir)) { Sleep(250); rec_rmdir(tmpdir); } } }
int relay_tee(PCStr(arg),int src,int dst1,int dst2,int *rccp,int *wccp1,int *wccp2) { int rcc,wcc,wc1; /* CStr(buf,0x4000); */ CStr(buf,0x10000); int isize = 0x4000; *wccp1 = 0; if( wccp2 ) *wccp2 = 0; /* rcc = read(src,buf,sizeof(buf)); */ rcc = read(src,buf,QVSSize(buf,isize)); if( rcc <= 0 && 0 <= top_fd(src,0) ){ int pop_fd(int fd,int rw); if( pop_fd(src,0) ){ syslog_ERROR("relay_tee(%d) -> pop_fd()\n",src); errno = EAGAIN; *rccp = 0; return -1; } } *rccp = rcc; if( rcc <= 0 ) { lastpackLeng = rcc; bzero(lastpack,sizeof(lastpack)); return rcc; } lastpackLeng = rcc; bcopy(buf,lastpack,8<rcc?8:rcc); if( dump_tcprelay ) bdump(src,dst1,buf,rcc); /* wcc = 0; while( wcc < rcc ){ wc1 = write(dst1,buf,rcc); if( wc1 <= 0 ) break; wcc += wc1; } */ wcc = writes(isize,src,dst1,buf,rcc,&wc1); *wccp1 = wcc; if( dst2 < 0 || wc1 <= 0 ) return wc1; /* wcc = 0; while( wcc < rcc ){ wc1 = write(dst2,buf,rcc); if( wc1 <= 0 ) break; wcc += wc1; } */ wcc = writes(isize,src,dst2,buf,rcc,&wc1); *wccp2 = wcc; return wc1; }
void c_basis::on_process(void* data, int size, mw_net_pipe* pipe) { if (size > 0 && ((char*)data)[0] == 'Q') { s_log()->info("loopbreak(0x%x)\r\n", ctid()); loopbreak(); return; } //1.优先处理重先绑定的 while (true) { CRawTcpConnection* con = pop_rebind(); if (con == NULL) break; con->on_rebind(); } //判断是否有连接关闭 while (true) { int32 fd = get_close(); if (fd == 0) break; MSocket::iterator pos = m_mSocket.find(fd); if (pos != m_mSocket.end()) { pos->second->on_close(EVUTIL_SOCKET_ERROR()); } } //判断是否有新连接到来 accept_fd fd; while ( libevent::get_instance()->g_fd(fd) ) { CRawTcpConnection* pcon = new CRawTcpConnection(fd.fd, fd.remote_ip); fd.sink->on_accept(pcon, fd.port); m_mSocket.insert(make_pair(fd.fd, pcon)); } //判断是否有新的连接 connect_fd cd; while ( libevent::get_instance()->g_cd(cd) ) { cd.sink->asyn_connect(cd.addr, cd.port); } //信息本线程所有连接信号 while (true) { int fd = pop_fd(); if (fd == 0) break; MSocket::iterator pos = m_mSocket.find(fd); if (pos != m_mSocket.end()) { CRawTcpConnection* con = pos->second; pos->second->on_signal(); } } }