if (baud_rate != -1)
{
- if (serial_setbaudrate (rs->remote_desc, baud_rate))
+ try
+ {
+ serial_setbaudrate (rs->remote_desc, baud_rate);
+ }
+ catch (const gdb_exception_error &)
{
/* The requested speed could not be set. Error out to
top level after closing remote_desc. Take care to
more than once. */
serial_close (rs->remote_desc);
rs->remote_desc = NULL;
- perror_with_name (name);
+ throw;
}
}
return;
}
-int
+void
ser_base_setbaudrate (struct serial *scb, int rate)
{
- return 0; /* Never fails! */
+ /* Never fails! */
}
int
extern void ser_base_print_tty_state (struct serial *scb,
serial_ttystate ttystate,
struct ui_file *stream);
-extern int ser_base_setbaudrate (struct serial *scb, int rate);
+extern void ser_base_setbaudrate (struct serial *scb, int rate);
extern int ser_base_setstopbits (struct serial *scb, int num);
extern int ser_base_setparity (struct serial *scb, int parity);
extern int ser_base_drain_output (struct serial *scb);
return (SetCommState (h, &state) != 0) ? 0 : -1;
}
-static int
+static void
ser_windows_setbaudrate (struct serial *scb, int rate)
{
HANDLE h = (HANDLE) _get_osfhandle (scb->fd);
DCB state;
if (GetCommState (h, &state) == 0)
- return -1;
+ throw_winerror_with_name ("call to GetCommState failed", GetLastError ());
state.BaudRate = rate;
- return (SetCommState (h, &state) != 0) ? 0 : -1;
+ if (SetCommState (h, &state) == 0)
+ throw_winerror_with_name ("call to SetCommState failed", GetLastError ());
}
static void
static int hardwire_open (struct serial *scb, const char *name);
static void hardwire_raw (struct serial *scb);
static int rate_to_code (int rate);
-static int hardwire_setbaudrate (struct serial *scb, int rate);
+static void hardwire_setbaudrate (struct serial *scb, int rate);
static int hardwire_setparity (struct serial *scb, int parity);
static void hardwire_close (struct serial *scb);
static int get_tty_state (struct serial *scb,
{
if (i)
{
- warning (_("Invalid baud rate %d. "
- "Closest values are %d and %d."),
- rate, baudtab[i - 1].rate, baudtab[i].rate);
+ error (_("Invalid baud rate %d. "
+ "Closest values are %d and %d."),
+ rate, baudtab[i - 1].rate, baudtab[i].rate);
}
else
{
- warning (_("Invalid baud rate %d. Minimum value is %d."),
- rate, baudtab[0].rate);
+ error (_("Invalid baud rate %d. Minimum value is %d."),
+ rate, baudtab[0].rate);
}
- return -1;
}
}
}
/* The requested speed was too large. */
- warning (_("Invalid baud rate %d. Maximum value is %d."),
- rate, baudtab[i - 1].rate);
- return -1;
+ error (_("Invalid baud rate %d. Maximum value is %d."),
+ rate, baudtab[i - 1].rate);
}
-static int
+static void
hardwire_setbaudrate (struct serial *scb, int rate)
{
struct hardwire_ttystate state;
int baud_code = rate_to_code (rate);
- if (baud_code < 0)
- {
- /* The baud rate was not valid.
- A warning has already been issued. */
- errno = EINVAL;
- return -1;
- }
-
if (get_tty_state (scb, &state))
- return -1;
+ perror_with_name ("could not get tty state");
cfsetospeed (&state.termios, baud_code);
cfsetispeed (&state.termios, baud_code);
- return set_tty_state (scb, &state);
+ if (set_tty_state (scb, &state))
+ perror_with_name ("could not set tty state");
}
static int
scb->ops->print_tty_state (scb, ttystate, stream);
}
-int
+void
serial_setbaudrate (struct serial *scb, int rate)
{
- return scb->ops->setbaudrate (scb, rate);
+ scb->ops->setbaudrate (scb, rate);
}
int
serial_ttystate ttystate,
struct ui_file *);
-/* Set the baudrate to the decimal value supplied. Returns 0 for
- success, -1 for failure. */
+/* Set the baudrate to the decimal value supplied. Throws exception
+ on error. */
-extern int serial_setbaudrate (struct serial *scb, int rate);
+extern void serial_setbaudrate (struct serial *scb, int rate);
/* Set the number of stop bits to the value specified. Returns 0 for
success, -1 for failure. */
int (*set_tty_state) (struct serial *, serial_ttystate);
void (*print_tty_state) (struct serial *, serial_ttystate,
struct ui_file *);
- int (*setbaudrate) (struct serial *, int rate);
+ void (*setbaudrate) (struct serial *, int rate);
int (*setstopbits) (struct serial *, int num);
/* Set the value PARITY as parity setting for serial object.
Return 0 in the case of success. */