src/server/daemon/sessionhandler.c

changeset 133
87b405d61f64
parent 129
fd324464f56f
child 135
471e28cca288
equal deleted inserted replaced
132:e9afb5387007 133:87b405d61f64
58 } 58 }
59 59
60 int connection_ssl_read(Connection *conn, void *buf, int len) { 60 int connection_ssl_read(Connection *conn, void *buf, int len) {
61 int ret = SSL_read(conn->ssl, buf, len); 61 int ret = SSL_read(conn->ssl, buf, len);
62 if(ret <= 0) { 62 if(ret <= 0) {
63 conn->ssl_error = ERR_get_error(); 63 conn->ssl_error = SSL_get_error(conn->ssl, ret);
64 } 64 }
65 return ret; 65 return ret;
66 } 66 }
67 67
68 int connection_ssl_write(Connection *conn, const void *buf, int len) { 68 int connection_ssl_write(Connection *conn, const void *buf, int len) {
69 int ret = SSL_write(conn->ssl, buf, len); 69 int ret = SSL_write(conn->ssl, buf, len);
70 if(ret <= 0) { 70 if(ret <= 0) {
71 conn->ssl_error = ERR_get_error(); 71 conn->ssl_error = SSL_get_error(conn->ssl, ret);
72 } 72 }
73 return ret; 73 return ret;
74 } 74 }
75 75
76 void connection_ssl_close(Connection *conn) { 76 void connection_ssl_close(Connection *conn) {
77 SSL_shutdown(conn->ssl); 77 int ret = SSL_shutdown(conn->ssl);
78 if(ret != 1) {
79 conn->ssl_error = SSL_get_error(conn->ssl, ret);
80 log_ereport(LOG_VERBOSE, "SSL_shutdown failed: %d", conn->ssl_error);
81 }
78 close(conn->fd); 82 close(conn->fd);
79 } 83 }
80 84
81 void connection_destroy(Connection *conn) { 85 void connection_destroy(Connection *conn) {
82 conn->close(conn); 86 conn->close(conn);
220 event->finish = evt_request_finish; 224 event->finish = evt_request_finish;
221 event->cookie = io; 225 event->cookie = io;
222 226
223 if(ev_pollin(ev, conn->fd, event) != 0) { 227 if(ev_pollin(ev, conn->fd, event) != 0) {
224 // TODO: ev_pollin should log, intercept some errors here 228 // TODO: ev_pollin should log, intercept some errors here
225 log_ereport(LOG_WARN, "ev_pollin failed: %s", strerror(errno)); 229 log_ereport(LOG_FAILURE, "Cannot enqueue connection");
226 close(conn->fd); 230 connection_destroy(conn);
227 // TODO: free stuff 231 // TODO: free stuff
228 } 232 }
229 } 233 }
230 234
231 int evt_request_input(event_handler_t *handler, event_t *event) { 235 int evt_request_input(event_handler_t *handler, event_t *event) {
240 r = conn->read( 244 r = conn->read(
241 conn, 245 conn,
242 buf->inbuf + buf->pos, 246 buf->inbuf + buf->pos,
243 buf->maxsize - buf->pos); 247 buf->maxsize - buf->pos);
244 if(r <= 0) { 248 if(r <= 0) {
249 if(conn->ssl) {
250 // SSL specific error handling
251 switch(conn->ssl_error) {
252 case SSL_ERROR_WANT_READ: {
253 event->poll = EVENT_POLLIN;
254 return 1;
255 }
256 case SSL_ERROR_WANT_WRITE: {
257 event->poll = EVENT_POLLOUT;
258 return 1;
259 }
260 }
261 }
262
245 event->finish = evt_request_error; 263 event->finish = evt_request_error;
246 return 0; 264 return 0;
247 } 265 }
248 //fwrite(buf->inbuf + buf->pos, 1, r, stdout); 266 //fwrite(buf->inbuf + buf->pos, 1, r, stdout);
249 //printf("\n"); 267 //printf("\n");
258 } else if(state == 1) { 276 } else if(state == 1) {
259 /* 277 /*
260 * we need more data -> return 1 to tell the event handler to 278 * we need more data -> return 1 to tell the event handler to
261 * continue polling 279 * continue polling
262 */ 280 */
281 event->poll = EVENT_POLLIN;
263 return 1; 282 return 1;
264 } 283 }
265 284
266 // we are done with reading 285 // we are done with reading
267 286

mercurial