/* provides state machine for echo negotiation * @returns new state of echo */ static int echoNegotiation(int currentState, int command, ushort writeDevice) { switch (currentState) { case TELNET_ECHO_OTHER_ECHOES: if (TELNET_WONT == command) { sendOption(writeDevice, TELNET_DONT, TELNET_ECHO); return TELNET_ECHO_NO_ECHO; } else if (TELNET_DO == command) { sendOption(writeDevice, TELNET_WONT, TELNET_ECHO); return TELNET_ECHO_OTHER_ECHOES; } break; case TELNET_ECHO_NO_ECHO: if (TELNET_DO == command) { sendOption(writeDevice, TELNET_WONT, TELNET_ECHO); return TELNET_ECHO_NO_ECHO; } else if (TELNET_WILL == command) { sendOption(writeDevice, TELNET_DO, TELNET_ECHO); return TELNET_ECHO_OTHER_ECHOES; } break; default: // Error, unknown state break; } return currentState; }
void UciEngine::startGame() { Q_ASSERT(supportsVariant(board()->variant())); m_moveStrings.clear(); if (board()->isRandomVariant()) m_startFen = board()->fenString(Chess::Board::ShredderFen); else m_startFen = board()->fenString(Chess::Board::XFen); QString uciVariant(variantToUci(board()->variant())); if (uciVariant != m_variantOption) { if (!m_variantOption.isEmpty()) sendOption(m_variantOption, false); m_variantOption = uciVariant; } if (!m_variantOption.isEmpty()) sendOption(m_variantOption, true); write("ucinewgame"); if (m_sendOpponentsName) { QString opType = opponent()->isHuman() ? "human" : "computer"; QString value = QString("none none %1 %2") .arg(opType) .arg(opponent()->name()); sendOption("UCI_Opponent", value); } sendPosition(); }
thread telnetSend(ushort dev) { int ch; while (SYSERR != (ch = getc(stdin))) { /* close connection on CTRL + ] */ if (ch == TELNET_CHR_CLOSE) { printf("\nConnection closed by user.\n"); return OK; } /* Send Erase Character command instead of backspace */ if ((ch == '\b') || (ch == TELNET_CHR_DEL)) { sendOption(dev, TELNET_EC, '\0'); continue; } /* Send Erase Line command instead of CTRL + U */ if (ch == TELNET_CHR_EL) { sendOption(dev, TELNET_EL, '\0'); continue; } if (ch == '\n') { putc(dev, '\r'); } if (SYSERR == putc(dev, ch)) { printf("\nConnection closed by foreign host.\n"); return OK; } } return SYSERR; }
static void blatzClient(char *input, char *output) /* Send query message and dna to server and print result. */ { struct dnaLoad *dl = dnaLoadOpen(input); struct dnaSeq *seq; FILE *f = mustOpen(output, "w"); static struct optionSpec options[] = { BZP_CLIENT_OPTIONS }; int i; while ((seq = dnaLoadNext(dl)) != NULL) { /* Connect */ int sd = netMustConnect(host, port); FILE *sf = NULL; /* Send query command. */ netSendString(sd, "query"); /* Send options. */ for (i=0; i<ArraySize(options); ++i) sendOption(sd, options[i].name); /* Send sequence. */ if (optionExists("rna") || optionExists("unmask")) toUpperN(seq->dna, seq->size); else { if (seqIsLower(seq)) warn("Sequence %s is all lower case, and thus ignored. Use -unmask " "flag to unmask lower case sequence.", seq->name); } netSendString(sd, "seq"); netSendString(sd, seq->name); netSendHugeString(sd, seq->dna); verbose(1, "%s\n", seq->name); dnaSeqFree(&seq); /* Get and save response. */ sf = netFileFromSocket(sd); copyOpenFile(sf, f); carefulClose(&sf); /* Close connection */ close(sd); } dnaLoadClose(&dl); carefulClose(&f); }
thread telnetRecv(ushort dev) { int ch; bool sgaRemoteEnabled = FALSE; bool sgaLocalEnabled = FALSE; int echoState = TELNET_ECHO_NO_ECHO; /* read until connection closed */ while (read(dev, &ch, 1) != SYSERR) { switch (ch) { case TELNET_IAC: switch (getc(dev)) { case TELNET_WILL: /* get single raw characters if server agrees to echo option */ if (((ch = getc(dev)) == TELNET_ECHO) && (echoState == TELNET_ECHO_NO_ECHO)) { sendOption(dev, TELNET_DO, TELNET_ECHO); echoState = TELNET_ECHO_OTHER_ECHOES; /* set local TTY to only print remotely echoed chars */ control(stdin, TTY_CTRL_CLR_IFLAG, TTY_ECHO, NULL); control(stdin, TTY_CTRL_SET_IFLAG, TTY_IRAW, NULL); } else if ((ch == TELNET_SUPPRESS_GA) && !(sgaRemoteEnabled)) { sendOption(dev, TELNET_DO, TELNET_SUPPRESS_GA); sgaRemoteEnabled = TRUE; } else { sendOption(dev, TELNET_DONT, ch); } break; case TELNET_DO: if ((ch = getc(dev)) == SYSERR) { printf("\nConnection closed by foreign host.\n"); return OK; } else if (ch == TELNET_SUPPRESS_GA && !(sgaLocalEnabled)) { sendOption(dev, TELNET_WILL, TELNET_SUPPRESS_GA); sgaLocalEnabled = TRUE; } else { sendOption(dev, TELNET_WONT, ch); } break; case TELNET_WONT: if (SYSERR == (ch = getc(dev))) { printf("\nConnection closed by foreign host.\n"); return OK; } else if (TELNET_ECHO == ch) { echoState = echoNegotiation(echoState, TELNET_DONT, dev); /* set local TTY to local echo */ if (echoState == TELNET_ECHO_NO_ECHO) { control(stdin, TTY_CTRL_SET_IFLAG, TTY_ECHO, NULL); control(stdin, TTY_CTRL_CLR_IFLAG, TTY_IRAW, NULL); } } else if ((TELNET_SUPPRESS_GA == ch) && sgaRemoteEnabled) { sendOption(dev, TELNET_DONT, TELNET_SUPPRESS_GA); sgaRemoteEnabled = FALSE; } break; case TELNET_DONT: if (SYSERR == (ch = getc(dev))) { printf("\nConnection closed by foreign host.\n"); return OK; } else if (TELNET_ECHO == ch) { echoState = echoNegotiation(echoState, TELNET_DONT, dev); } else if ((TELNET_SUPPRESS_GA == ch) && sgaLocalEnabled) { sendOption(dev, TELNET_WONT, TELNET_SUPPRESS_GA); sgaLocalEnabled = FALSE; } break; case TELNET_IAC: /* escaped IAC sequence, so print a single IAC char */ printf("%c", TELNET_IAC); break; case TELNET_AYT: /* reply to server with useless data so it doesn't print */ putc(dev, '\0'); break; case TELNET_EC: /* delete last char */ printf("%c", '\b'); break; case SYSERR: printf("\nConnection closed by foreign host.\n"); return OK; default: break; } break; default: printf("%c", ch); break; } } printf("\nConnection closed by foreign host.\n"); return OK; }
int main () { int m=2; int n=2; int nclin=0; int ldC=n; int ldA=m; double* C = new double [n]; C[0]=0; C[1]=0; double* bl = new double [n]; bl[0]=-10; bl[1]=-10; double* bu = new double [n]; bu[0]=10; bu[1]=10; double* cvec = new double [n]; int* istate = new int [n+nclin]; int* kx = new int[n]; double* x = new double [n]; x[0]=0; x[1]=0; double* A = new double [m*n]; A[0]=-1;A[1]=-2; A[2]=-2;A[3]=-1; double* b = new double [m]; b[0]=-1; b[1]=1; int inform; int iter; double obj; double* clamda = new double [n+nclin]; int* iw = new int[n+100]; int leniw=n+100; double* w = new double[n+100]; int lenw=10*n+100; sendOption("Print Level = 100"); lssol_(&m, &n, &nclin, &ldC, &ldA, C, bl, bu, cvec, istate, kx, x, A, b, &inform, &iter, &obj, clamda, iw, &leniw, w, &lenw); bool result = ((fabs(x[0] + 1) < 1e-9) && (fabs(x[1] - 1) < 1e-9)); delete[] w; delete[] iw; delete[] clamda; delete[] b; delete[] A; delete[] x; delete[] kx; delete[] istate; delete[] cvec; delete[] bu; delete[] bl; delete[] C; if (result == true) return 0; else return 1; }
int satipRTSP::sendRequest(int request) { if (m_wait_response) { DEBUG(MSG_MAIN, "Now waitng response, skip sendRequest(%d)\n", request); return RTSP_FAILED; } stopTimerKeepAliveMessage(); // before send request, stop keep alive message timer. int res = RTSP_ERROR; switch(request) { case RTSP_REQUEST_OPTION: res = sendOption(); break; case RTSP_REQUEST_SETUP: res = sendSetup(); break; case RTSP_REQUEST_PLAY: res = sendPlay(); break; case RTSP_REQUEST_TEARDOWN: res = sendTearDown(); break; case RTSP_REQUEST_DESCRIBE: res = sendDescribe(); break; default: DEBUG(MSG_MAIN, "Unknown request!\n"); break; } if (res == RTSP_OK) { m_wait_response = true; m_rtsp_request = request; startTimerResetConnect(2000); // server connect timer start } else { switch(request) { case RTSP_REQUEST_OPTION: DEBUG(MSG_MAIN, "RTSP SEND OPTION is failed! try reconnect.\n"); break; case RTSP_REQUEST_SETUP: DEBUG(MSG_MAIN, "RTSP SEND SETUP is failed! try reconnect.\n"); break; case RTSP_REQUEST_PLAY: DEBUG(MSG_MAIN, "RTSP SEND PLAY is failed! try reconnect.\n"); break; case RTSP_REQUEST_TEARDOWN: DEBUG(MSG_MAIN, "RTSP SEND TEARDOWN is failed! try reconnect.\n"); break; case RTSP_REQUEST_DESCRIBE: DEBUG(MSG_MAIN, "RTSP SEND DESCRIBE is failed! try reconnect.\n"); break; default: break; } resetConnect(); } return res; }