mirror of
https://github.com/sheumann/hush.git
synced 2024-12-27 01:32:08 +00:00
Aurelien Jacobs pointed out inline functions that could be removed. Doing so
shrank the code a bit.
This commit is contained in:
parent
e5e1a10cd3
commit
399d45f1c6
@ -39,7 +39,6 @@
|
||||
#define EOT 0x04
|
||||
#define ACK 0x06
|
||||
#define NAK 0x15
|
||||
#define CAN 0x18
|
||||
#define BS 0x08
|
||||
|
||||
/*
|
||||
@ -57,18 +56,6 @@ Cf:
|
||||
#define TIMEOUT_LONG 10
|
||||
#define MAXERRORS 10
|
||||
|
||||
static inline void write_byte(int fd, char cc) {
|
||||
write(fd, &cc, 1);
|
||||
}
|
||||
|
||||
static inline void write_flush(int fd) {
|
||||
tcdrain(fd);
|
||||
}
|
||||
|
||||
static inline void read_flush(int fd) {
|
||||
tcflush(fd, TCIFLUSH);
|
||||
}
|
||||
|
||||
static int read_byte(int fd, unsigned int timeout) {
|
||||
char buf[1];
|
||||
int n;
|
||||
@ -99,11 +86,11 @@ static int receive(char *error_buf, size_t error_buf_size,
|
||||
#define note_error(fmt,args...) \
|
||||
snprintf(error_buf, error_buf_size, fmt,##args)
|
||||
|
||||
read_flush(ttyfd);
|
||||
/* Flush pending input */
|
||||
tcflush(ttyfd, TCIFLUSH);
|
||||
|
||||
/* Ask for CRC; if we get errors, we will go with checksum */
|
||||
write_byte(ttyfd, nak);
|
||||
write_flush(ttyfd);
|
||||
write(ttyfd, &nak, 1);
|
||||
|
||||
for (;;) {
|
||||
int blockBegin;
|
||||
@ -126,8 +113,8 @@ static int receive(char *error_buf, size_t error_buf_size,
|
||||
break;
|
||||
|
||||
case EOT:
|
||||
write_byte(ttyfd, ACK);
|
||||
write_flush(ttyfd);
|
||||
nak = ACK;
|
||||
write(ttyfd, &nak, 1);
|
||||
goto done;
|
||||
|
||||
default:
|
||||
@ -232,8 +219,8 @@ static int receive(char *error_buf, size_t error_buf_size,
|
||||
|
||||
next:
|
||||
errors = 0;
|
||||
write_byte(ttyfd, ACK);
|
||||
write_flush(ttyfd);
|
||||
nak = ACK;
|
||||
write(ttyfd, &nak, 1);
|
||||
continue;
|
||||
|
||||
error:
|
||||
@ -241,7 +228,6 @@ static int receive(char *error_buf, size_t error_buf_size,
|
||||
errors++;
|
||||
if (errors == MAXERRORS) {
|
||||
/* Abort */
|
||||
int i;
|
||||
|
||||
// if using crc, try again w/o crc
|
||||
if (nak == 'C') {
|
||||
@ -254,17 +240,15 @@ static int receive(char *error_buf, size_t error_buf_size,
|
||||
note_error("too many errors; giving up");
|
||||
|
||||
fatal:
|
||||
for (i = 0; i < 5; i ++)
|
||||
write_byte(ttyfd, CAN);
|
||||
for (i = 0; i < 5; i ++)
|
||||
write_byte(ttyfd, BS);
|
||||
write_flush(ttyfd);
|
||||
/* 5 CAN followed by 5 BS */
|
||||
write(ttyfd, "\030\030\030\030\030\010\010\010\010\010", 10);
|
||||
return -1;
|
||||
}
|
||||
|
||||
read_flush(ttyfd);
|
||||
write_byte(ttyfd, nak);
|
||||
write_flush(ttyfd);
|
||||
/* Flush pending input */
|
||||
tcflush(ttyfd, TCIFLUSH);
|
||||
|
||||
write(ttyfd, &nak, 1);
|
||||
}
|
||||
|
||||
done:
|
||||
|
Loading…
Reference in New Issue
Block a user