Showing
4 changed files
with
22 additions
and
3 deletions
... | ... | @@ -129,12 +129,28 @@ serverRun(Server this) |
129 | 129 | * handle writes |
130 | 130 | */ |
131 | 131 | if (0 != ((this->fds)[i].revents & POLLOUT)) { |
132 | - write( | |
132 | + int size; | |
133 | + | |
134 | + size = write( | |
133 | 135 | (this->fds)[i].fd, |
134 | 136 | (this->conns)[fd].wbuf, |
135 | 137 | strlen((this->conns)[fd].wbuf)); |
136 | - (this->fds)[i].events = (this->fds)[i].events & ~POLLOUT; | |
137 | - serverCloseConn(this, i); | |
138 | + | |
139 | + if (size == strlen((this->conns)[fd].wbuf) || | |
140 | + -1 == size) { | |
141 | + if (-1 == size) { | |
142 | + loggerLog(this->logger, LOGGER_ERR, | |
143 | + "write error, closing connection"); | |
144 | + } | |
145 | + | |
146 | + (this->fds)[i].events = (this->fds)[i].events & ~POLLOUT; | |
147 | + serverCloseConn(this, i); | |
148 | + } | |
149 | + else { | |
150 | + memmove((this->conns)[fd].wbuf, | |
151 | + (this->conns)[fd].wbuf + size, | |
152 | + strlen((this->conns)[fd].wbuf) - size + 1); | |
153 | + } | |
138 | 154 | } |
139 | 155 | } |
140 | 156 | } | ... | ... |
Please
register
or
login
to post a comment