Fix some bugs and add close_later() methods in RSocket

Uglify d3.js (the smaller the better)
Fix premature socket close on http reply with a hack
This commit is contained in:
pancake 2012-12-10 16:25:57 +01:00
parent e22ac507ea
commit c98cc9d1ab
7 changed files with 45 additions and 6554 deletions

View File

@ -477,7 +477,7 @@ else
}
if (showhdr && fmt==1)
r_cons_printf ("}\n");
if (fmt==2) r_cons_printf ("]");
if (fmt==2) r_cons_printf ("]\n");
}
static void fcn_list_bbs(RAnalFunction *fcn) {

View File

@ -140,7 +140,7 @@ R_API int r_core_rtr_http(RCore *core, int launch) {
} else {
r_socket_http_response (rs, 404, "Invalid protocol", 0, NULL);
}
r_socket_http_close (rs);
r_socket_http_close_later (rs);
}
r_socket_free (s);
r_cons_break_end ();

View File

@ -37,6 +37,7 @@ R_API int r_socket_connect (RSocket *s, const char *host, const char *port, int
R_API int r_socket_unix_listen (RSocket *s, const char *file);
#endif
R_API int r_socket_close (RSocket *s);
R_API int r_socket_close_later (RSocket *s);
R_API int r_socket_free (RSocket *s);
R_API int r_socket_listen (RSocket *s, const char *port, const char *certfile);
R_API RSocket *r_socket_accept (RSocket *s);
@ -83,5 +84,6 @@ typedef struct r_socket_http_request {
R_API RSocketHTTPRequest *r_socket_http_accept (RSocket *s, int timeout);
R_API void r_socket_http_response (RSocketHTTPRequest *rs, int code, const char *out, int x, const char *headers);
R_API void r_socket_http_close (RSocketHTTPRequest *rs);
R_API void r_socket_http_close_later (RSocketHTTPRequest *rs);
#endif
#endif

View File

@ -69,10 +69,22 @@ R_API void r_socket_http_response (RSocketHTTPRequest *rs, int code, const char
if (len<1) len = out? strlen (out): 0;
if (!headers) headers = "";
r_socket_printf (rs->s, "HTTP/1.0 %d %s\n%s"
"Content-Length: %d\n\n", code, strcode, headers, len);
"Connection: close\nContent-Length: %d\n\n", code, strcode, headers, len);
if (out && len>0) r_socket_write (rs->s, (void*)out, len);
}
R_API void r_socket_http_close_later (RSocketHTTPRequest *rs) {
#if __UNIX__
if (!fork ()) {
sleep (3);
r_socket_http_close (rs);
exit (0);
}
#else
r_socket_http_close (rs);
#endif
}
/* close client socket and free struct */
R_API void r_socket_http_close (RSocketHTTPRequest *rs) {
r_socket_free (rs->s);
@ -92,7 +104,7 @@ int main() {
return 1;
}
for (;;) {
RSocketHTTPRequest *rs = r_socket_http_accept (s);
RSocketHTTPRequest *rs = r_socket_http_accept (s, 0);
if (!rs) continue;
if (!strcmp (rs->method, "GET")) {
r_socket_http_response (rs, 200,

View File

@ -216,17 +216,31 @@ R_API int r_socket_close (RSocket *s) {
WSACleanup ();
ret = closesocket (s->fd);
#else
shutdown (s->fd, SHUT_RDWR);
//shutdown (s->fd, SHUT_RDWR);
ret = close (s->fd);
#endif
}
#if HAVE_LIB_SSL
if (s->is_ssl && s->sfd)
SSL_shutdown (s->sfd);
if (s->is_ssl && s->sfd) {
SSL_free (s->sfd);
s->sfd = NULL;
}
#endif
return ret;
}
R_API int r_socket_close_later (RSocket *s) {
#if __UNIX__
if (!fork ()) {
sleep (3);
r_socket_close (s);
exit (0);
}
#else
r_socket_close (s);
#endif
}
R_API int r_socket_free (RSocket *s) {
int res = r_socket_close (s);
#if HAVE_LIB_SSL
@ -373,7 +387,7 @@ R_API int r_socket_ready(RSocket *s, int secs, int usecs) {
FD_SET (s->fd, &rfds);
tv.tv_sec = secs;
tv.tv_usec = usecs;
if (select (1, &rfds, NULL, NULL, &tv) == -1)
if (select (s->fd+1, &rfds, NULL, NULL, &tv) == -1)
return -1;
return FD_ISSET (0, &rfds);
#else
@ -408,17 +422,19 @@ R_API char *r_socket_to_string(RSocket *s) {
R_API int r_socket_write(RSocket *s, void *buf, int len) {
int ret, delta = 0;
for (;;) {
int b = 65536; // Use MTU 1500?
if (b>len) b = len;
#if HAVE_LIB_SSL
if (s->is_ssl)
if (s->bio)
ret = BIO_write (s->bio, buf+delta, len);
ret = BIO_write (s->bio, buf+delta, b);
else
ret = SSL_write (s->sfd, buf+delta, len);
ret = SSL_write (s->sfd, buf+delta, b);
else
#endif
ret = send (s->fd, buf+delta, len, 0);
if (ret == 0)
return -1;
ret = send (s->fd, buf+delta, len, MSG_NOSIGNAL);
//if (ret == 0) return -1;
if (!ret) continue;
if (ret == len)
return len;
if (ret<0)

4646
shlr/www/d3/d3.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long