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