Browse Source

handle buffer correctly

pull/4/merge
Max Lv 11 years ago
parent
commit
bbd7ccc740
2 changed files with 10 additions and 3 deletions
  1. 2
      src/Makefile.am
  2. 11
      src/server.c

2
src/Makefile.am

@ -9,6 +9,6 @@ ss_local_LDADD = $(top_builddir)/libev/libev.la
ss_local_LDADD += $(top_builddir)/libasyncns/libasyncns.la
ss_server_LDADD = $(top_builddir)/libev/libev.la
ss_server_LDADD += $(top_builddir)/libasyncns/libasyncns.la
AM_CFLAGS = -O2 -Wall -fno-strict-aliasing
AM_CFLAGS = -g -O2 -Wall -fno-strict-aliasing
AM_CFLAGS += -I$(top_builddir)/libev
AM_CFLAGS += -I$(top_builddir)/libasyncns

11
src/server.c

@ -250,8 +250,8 @@ static void server_recv_cb (EV_P_ ev_io *w, int revents) {
// XXX: should handel buffer carefully
if (r > offset) {
remote->buf_len = r - offset;
memcpy(remote->buf, server->buf + offset, remote->buf_len);
server->buf_len = r - offset;
memcpy(server->buf, server->buf + offset, server->buf_len);
}
server->stage = 4;
@ -370,6 +370,13 @@ static void server_resolve_cb(EV_P_ ev_timer *watcher, int revents) {
server->remote = remote;
remote->server = server;
// XXX: should handel buffer carefully
if (server->buf_len > 0) {
memcpy(remote->buf, server->buf, server->buf_len);
remote->buf_len = server->buf_len;
server->buf_len = 0;
}
// listen to remote connected event
ev_io_start(EV_A_ &remote->send_ctx->io);
ev_timer_start(EV_A_ &remote->send_ctx->watcher);

Loading…
Cancel
Save