extern int tcsetattr( int fildes, int optact, const struct termios *termios_p ) { cyg_file *fp; int ret; setattr_struct attr; int len = sizeof( attr ); CYG_REPORT_FUNCTYPE( "returning %d" ); CYG_REPORT_FUNCARG3( "fildes=%d, optact=%d, termios_p=%08x", fildes, optact, termios_p ); CYG_CHECK_DATA_PTRC( termios_p ); if ( !isatty(fildes) ) { errno = ENOTTY; CYG_REPORT_RETVAL( -1 ); return -1; } if ( (optact != TCSANOW) && (optact != TCSADRAIN) && (optact != TCSAFLUSH) ) { errno = EINVAL; CYG_REPORT_RETVAL( -1 ); return -1; } fp = cyg_fp_get( fildes ); if ( NULL == fp ) { errno = EBADF; CYG_REPORT_RETVAL( -1 ); return -1; } attr.termios_p = termios_p; attr.optact = optact; ret = fp->f_ops->fo_setinfo( fp, CYG_IO_SET_CONFIG_TERMIOS, &attr, len); cyg_fp_free( fp ); if ( ret > 0 ) { errno = ret; CYG_REPORT_RETVAL( -1 ); return -1; } CYG_REPORT_RETVAL( 0 ); return 0; } // tcsetattr()
externC void cyg_drv_interrupt_configure( cyg_vector_t vector, cyg_bool_t level, cyg_bool_t up ) { CYG_REPORT_FUNCTION(); CYG_REPORT_FUNCARG3("vector = %d, level = %d, up = %d", vector, level, up); CYG_ASSERT( vector >= CYGNUM_HAL_ISR_MIN, "Invalid vector"); CYG_ASSERT( vector <= CYGNUM_HAL_ISR_MAX, "Invalid vector"); HAL_INTERRUPT_CONFIGURE( vector, level, up ); CYG_REPORT_RETURN(); }
/* Send the query to the server and read the response back. Return -1 if it fails, otherwise put the response back in msg and return the length of the response. */ static int send_recv(char * msg, int len, int msglen) { struct dns_header *dns_hdr; struct timeval timeout; int finished = false; int backoff = 2; fd_set readfds; int written; int ret; CYG_REPORT_FUNCNAMETYPE( "send_recv", "returning %d" ); CYG_REPORT_FUNCARG3( "msg=%08x, len=%d, msglen", msg, len, msglen ); CYG_CHECK_DATA_PTR( msg, "msg is not a valid pointer!" ); dns_hdr = (struct dns_header *) msg; do { written = write(s, msg, len); if (written < 0 || (written!=len)) { ret = -1; break; } FD_ZERO(&readfds); FD_SET(s, &readfds); timeout.tv_sec = backoff; timeout.tv_usec = 0; backoff = backoff << 1; ret = select(s+1, &readfds, NULL, NULL, &timeout); if (ret < 0) { ret = -1; break; } /* Timeout */ if (ret == 0) { if (backoff > 16) { h_errno = TRY_AGAIN; ret = -1; break; } } if (ret == 1) { ret = read(s, msg, msglen); if (ret < 0) { ret = -1; break; } /* Reply to an old query. Ignore it */ if (ntohs(dns_hdr->id) != (id-1)) { continue; } finished = true; } } while (!finished); CYG_REPORT_RETVAL( ret ); return ret; }