Little opt

This commit is contained in:
angt
2015-11-30 16:07:13 +01:00
parent 2f2e5e6f99
commit 22a6b511f7

View File

@@ -828,12 +828,6 @@ int main (int argc, char **argv)
FD_SET(sock.fd, &rfds);
if (buffer_read_size(&tun.read) || blk_count)
FD_SET(sock.fd, &wfds);
if (buffer_read_size(&sock.read))
FD_SET(tun.fd, &wfds);
if (select(sock.fd+1, &rfds, &wfds, NULL, NULL)==-1) {
if (errno==EINTR)
continue;
@@ -889,13 +883,13 @@ int main (int argc, char **argv)
}
}
while (1) {
buffer_shift(&tun.read);
while (blk_count) {
if (!blks[blk_read].size) {
blk_read++;
continue;
}
if (!stop_loop) {
for (; blk_count; blk_read++) {
if (!blks[blk_read].size)
break;
if (buffer_write_size(&tun.read)<blks[blk_read].size)
break;
@@ -903,24 +897,33 @@ int main (int argc, char **argv)
byte_cpy(tun.read.write, blks[blk_read].data, blks[blk_read].size);
tun.read.write += blks[blk_read].size;
blks[blk_read++].size = 0;
blks[blk_read].size = 0;
blk_count--;
}
gt_encrypt(&ctx, &sock.write, &tun.read);
}
if (!buffer_read_size(&sock.write))
break;
if (buffer_read_size(&sock.write)) {
ssize_t r = fd_write(sock.fd, sock.write.read,
buffer_read_size(&sock.write));
if (r>0) {
sock.write.read += r;
} else if (!r) {
} else {
if (!r) {
stop_loop |= (1<<2);
} else {
FD_SET(sock.fd, &wfds);
}
} else {
if (stop_loop && !(stop_loop>>2)) {
break;
}
}
if (stop_loop && !buffer_read_size(&sock.write)) {
if (!(stop_loop&(1<<2))) {
stop_loop |= (1<<2);
shutdown(sock.fd, SHUT_WR);
gt_log("%s: shutdown\n", sockname);