/* Read the rest of the line into linebuf so we can print it all in an error condition [Ash] */ void flushRestOfLine(void) { FILE *filein; int c = 'a'; extern int wouldBlock(void); if (Inp_Dev->newline) { Inp_Dev->linebuf[Inp_Dev->linebufend] = '\0'; /* clear the unwanted \n */ return; /* already have the complete line */ } /* This case can occur if tkeden is interrupted with ctrl-c */ if (!(Inp_Dev->ptr)) return; /* This wouldBlock stuff might be invalidated by the above newline logic, I'm not sure. I'll leave it in anyway. [Ash] */ if (Inp_Dev->type == FILE_DEV) { filein = (FILE *) Inp_Dev->ptr; /* if the whole line has already been read in, then doing a getc() would cause a block */ if (filein == stdin) { #if defined(TTYEDEN) && defined(HAVE_READLINE) if (rl_getc_wouldBlock()) return; #else if (wouldBlock()) return; #endif } } while (isprint(c)) { switch (Inp_Dev->type) { case FILE_DEV: #ifdef TTYEDEN #ifdef HAVE_READLINE if (filein == stdin && Inp_Dev->usereadline) c = rl_getc_wrapper(); else #endif /* HAVE_READLINE */ c = getc(filein); #else c = getc(filein); #endif break; case STRING_DEV: c = *(Inp_Dev->ptr)++; break; } append_linebuf(c); } /* Last character read was invalid */ Inp_Dev->linebuf[Inp_Dev->linebufend] = '\0'; }
Socket* SSLTCPSocket::accept() { if (endPoint != LISTENER) return NULL; SOCKET client; client = AcceptConnection(sock); if (client == -1 && !wouldBlock()) { setFatalError(); return NULL; } else if (client == -1 && wouldBlock()) { return NULL; } SSLTCPSocket* sslClient = new SSLTCPSocket(SERVER); if (!sslClient->setFD(client)) { delete sslClient; return NULL; } return sslClient; }
String getLine(){ const bool rl=false; if(rl){ char* mbs=readline((char*)"> "); if(!mbs) return emptyString; else{ add_history(mbs); String r=::newString(mbs);r.push('\n'); free(mbs); return r; } }else{ // each line is supposed < in length than 0x1000. static int cnt=0; char mbs[0x200];ssize_t n=0; #ifndef ndebug memset(&mbs,0xAB,sizeof(mbs)); #endif #define fileError 12 if( true ){ //&ETs[0]==this || cnt>=10000000){ for(int i=0x10;--i>=0 & n==0;){ while(-1==(n=::read(et::in,mbs,sizeof(mbs)-1))) if(wouldBlock()) stopETs.wait(); // if we arrive here it means that n is 0 or more // bellow is a delay in order to get delayed characters eventually available. usleep(100000); if(n!=0){ int n1=::read(et::in,mbs+n,sizeof(mbs)-1-n);if(n1!=-1) n+=n1; } clearTelnetCodes(mbs,n); } }else{ stopETs.wait(); const char* cmd="`bello' `brutto' | drop \n"; n=strlen(cmd); memcpy(mbs,cmd,n); } String r=::newString(mbs,n); return r; } }