static uint8_t receive_one_byte ( void ) { assert( connection_socket != -1 ); try { bool end_of_file; const uint8_t c = read_one_byte( connection_socket, &end_of_file ); if ( end_of_file ) throw std::runtime_error( "The remote server closed the connection." ); return c; } catch ( const std::exception & e ) { throw std::runtime_error( format_msg( "Error reading from the JTAG socket: %s", e.what() ) ); } }
static PyObject* py_read_string(PyObject* self, PyObject* args) { int fd; long timeout; char result[1024]; PyArg_ParseTuple(args, "il", &fd, &timeout); char *terminators = "\n\r"; unsigned long maximun_time = current_time_in_seconds() + timeout; int goahead=1; char c; int terminator_idx = 0; int result_idx = 0; result[0] = '\0'; while(goahead && (current_time_in_seconds() < maximun_time)){ c=read_one_byte(fd); if (c !=-1){ /* Compruebo si es un terminador*/ for(terminator_idx=0;terminator_idx<strlen(terminators);terminator_idx++) { if(c==terminators[terminator_idx]) goahead=0; } if (goahead == 0 && result_idx ==0) { //ignoro los terminadores al comienzo d ela cadena goahead =1; }else if(goahead){ result[result_idx++] = c; result[result_idx] = '\0'; } } } if(goahead){ printf ("TIMEOUT ERROR '%s' \n", result); return Py_BuildValue("s", NULL); }else{ return Py_BuildValue("s", result); } }