ry / ebb fork watch download tarball
public this repo is viewable by everyone
Description: web server
Homepage: http://ebb.rubyforge.org
Clone URL: git://github.com/ry/ebb.git
small bug fixes
Ryan Dahl (author)
2 months ago
commit  833f936c0f410b9c66edcccbceb177f0058bb722
tree    9f77fc099d902da94ebed9cdad23726f074bb4e0
parent  bdee84b3f95a6ac6e9632090f7095bd655af3288
...
42
43
44
 
 
 
 
 
 
 
 
 
45
46
47
...
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
0
@@ -42,6 +42,15 @@ module Daemonizable
0
     base.extend ClassMethods
0
   end
0
   
0
+ def daemonizable_init(options)
0
+ pid_file = options[:pid_file]
0
+ log_file = options[:log_file]
0
+ if options[:daemonize]
0
+ change_privilege options[:user], options[:group] if options[:user] && options[:group]
0
+ daemonize
0
+ end
0
+ end
0
+
0
   def pid
0
     File.exist?(pid_file) ? open(pid_file).read : nil
0
   end
...
70
71
72
73
74
75
76
77
78
79
80
81
 
 
82
83
84
...
103
104
105
106
107
 
108
109
110
...
117
118
119
 
120
121
122
...
70
71
72
 
 
73
 
 
 
 
 
74
75
76
77
78
79
...
98
99
100
 
 
101
102
103
104
...
111
112
113
114
115
116
117
0
@@ -70,15 +70,10 @@ module Ebb
0
     def initialize(app, options={})
0
       @socket = options[:socket]
0
       @port = (options[:port] || 4001).to_i
0
- pid_file = options[:pid_file]
0
- log_file = options[:log_file]
0
       @timeout = options[:timeout]
0
-
0
- if options[:daemonize]
0
- change_privilege options[:user], options[:group] if options[:user] && options[:group]
0
- daemonize
0
- end
0
       @app = app
0
+
0
+ daemonizable_init(options)
0
       FFI::server_initialize(self)
0
     end
0
     
0
@@ -103,8 +98,7 @@ module Ebb
0
       client.write "\r\n"
0
       
0
       # Not many apps use streaming yet so i'll hold off on that feature
0
- # until the rest of ebb is more developed
0
- # Yes, I know streaming responses are very cool.
0
+ # until the rest of ebb is more developed.
0
       if body.kind_of?(String)
0
         client.write body
0
       else
0
@@ -117,6 +111,7 @@ module Ebb
0
       trap('INT') { @running = false }
0
       
0
       if @socket
0
+ raise NotImplemented
0
         FFI::server_listen_on_socket(self, @socket) or raise "Problem listening on socket #{@socket}"
0
       else
0
         FFI::server_listen_on_port(self, @port) or raise "Problem listening on port #{@port}"
...
64
65
66
67
 
68
69
70
...
175
176
177
178
 
179
180
181
...
199
200
201
202
 
203
204
205
...
217
218
219
220
 
221
222
223
...
245
246
247
248
 
249
250
251
...
299
300
301
302
 
303
304
305
...
311
312
313
314
 
315
316
317
...
337
338
339
340
 
341
342
343
...
426
427
428
429
 
430
431
432
433
 
 
434
435
436
437
438
439
 
 
 
440
441
442
...
510
511
512
513
 
514
515
516
517
518
 
519
520
521
...
524
525
526
527
 
528
529
530
...
532
533
534
535
 
536
537
538
...
620
621
622
623
624
625
 
 
 
626
627
628
...
701
702
703
704
 
705
706
707
...
64
65
66
 
67
68
69
70
...
175
176
177
 
178
179
180
181
...
199
200
201
 
202
203
204
205
...
217
218
219
 
220
221
222
223
...
245
246
247
 
248
249
250
251
...
299
300
301
 
302
303
304
305
...
311
312
313
 
314
315
316
317
...
337
338
339
 
340
341
342
343
...
426
427
428
 
429
430
431
 
 
432
433
434
 
 
 
 
 
435
436
437
438
439
440
...
508
509
510
 
511
512
513
514
515
 
516
517
518
519
...
522
523
524
 
525
526
527
528
...
530
531
532
 
533
534
535
536
...
618
619
620
 
 
 
621
622
623
624
625
626
...
699
700
701
 
702
703
704
705
0
@@ -64,7 +64,7 @@ int env_has_error(ebb_client *client)
0
 #define DEF_MAX_LENGTH(N,length) const size_t MAX_##N##_LENGTH = length; const char *MAX_##N##_LENGTH_ERR = "HTTP Parse Error: HTTP element " # N " is longer than the " # length " allowed length."
0
 
0
 /** Validates the max length of given input and throws an exception if over. */
0
-#define VALIDATE_MAX_LENGTH(len, N) if(len > MAX_##N##_LENGTH) { env_error(client); ebb_info(MAX_##N##_LENGTH_ERR); }
0
+#define VALIDATE_MAX_LENGTH(len, N) if(len > MAX_##N##_LENGTH) { env_error(client); g_message(MAX_##N##_LENGTH_ERR); }
0
 
0
 /* Defines the maximum allowed lengths for various input elements.*/
0
 DEF_MAX_LENGTH(FIELD_NAME, 256);
0
@@ -175,7 +175,7 @@ void on_timeout(struct ev_loop *loop, ev_timer *watcher, int revents)
0
   
0
   ebb_client_close(client);
0
 #ifdef DEBUG
0
- ebb_info("peer timed out");
0
+ g_message("peer timed out");
0
 #endif
0
 }
0
 
0
@@ -199,7 +199,7 @@ void* read_body_into_file(void *_client)
0
   
0
   sprintf(client->upload_file_filename, "/tmp/ebb_upload_%010d", id++);
0
   tmpfile = fopen(client->upload_file_filename, "w+");
0
- if(tmpfile == NULL) ebb_error("Cannot open tmpfile %s", client->upload_file_filename);
0
+ if(tmpfile == NULL) g_message("Cannot open tmpfile %s", client->upload_file_filename);
0
   client->upload_file = tmpfile;
0
   
0
   size_t body_head_length = client->read - client->parser.nread;
0
@@ -217,7 +217,7 @@ void* read_body_into_file(void *_client)
0
     written += r;
0
   }
0
   
0
- // ebb_debug("wrote request header to file. written: %d, content_length: %d", written, client->content_length);
0
+ // g_debug("wrote request header to file. written: %d, content_length: %d", written, client->content_length);
0
   
0
   int bufsize = 5*1024;
0
   char buffer[bufsize];
0
@@ -245,7 +245,7 @@ void* read_body_into_file(void *_client)
0
     written += received;
0
   }
0
   rewind(tmpfile);
0
- // ebb_debug("%d bytes written to file %s", written, client->upload_file_filename);
0
+ // g_debug("%d bytes written to file %s", written, client->upload_file_filename);
0
   return NULL;
0
 error:
0
   ebb_client_close(client);
0
@@ -299,7 +299,7 @@ void on_readable(struct ev_loop *loop, ev_io *watcher, int revents)
0
   }
0
   return;
0
 error:
0
- if(read < 0) ebb_warning("Error recving data: %s", strerror(errno));
0
+ if(read < 0) g_message("Error recving data: %s", strerror(errno));
0
   ebb_client_close(client);
0
 }
0
 
0
@@ -311,7 +311,7 @@ void on_request(struct ev_loop *loop, ev_io *watcher, int revents)
0
   assert(&server->request_watcher == watcher);
0
   
0
   if(EV_ERROR & revents) {
0
- ebb_info("on_request() got error event, closing server.");
0
+ g_message("on_request() got error event, closing server.");
0
     ebb_server_unlisten(server);
0
     return;
0
   }
0
@@ -337,7 +337,7 @@ void on_request(struct ev_loop *loop, ev_io *watcher, int revents)
0
   int count = 0;
0
   for(i = 0; i < EBB_MAX_CLIENTS; i++)
0
     if(server->clients[i].open) count += 1;
0
- ebb_debug("%d open connections", count);
0
+ g_debug("%d open connections", count);
0
 #endif
0
   client->open = TRUE;
0
   client->server = server;
0
@@ -426,17 +426,15 @@ void ebb_server_free(ebb_server *server)
0
 void ebb_server_unlisten(ebb_server *server)
0
 {
0
   if(server->open) {
0
- ebb_info("Stopping Ebb server");
0
+ //g_message("Stopping Ebb server");
0
     int i;
0
     ebb_client *client;
0
- for(i=0; i < EBB_MAX_CLIENTS; i++)
0
- ebb_client_close(client);
0
+ //for(i=0; i < EBB_MAX_CLIENTS; i++)
0
+ // ebb_client_close(client);
0
     ev_io_stop(server->loop, &server->request_watcher);
0
- if(server->fd > 0) {
0
- close(server->fd);
0
- if(server->socketpath)
0
- unlink(server->socketpath);
0
- }
0
+ close(server->fd);
0
+ if(server->socketpath)
0
+ unlink(server->socketpath);
0
     server->open = FALSE;
0
   }
0
 }
0
@@ -510,12 +508,12 @@ void on_client_writable(struct ev_loop *loop, ev_io *watcher, int revents)
0
   ssize_t sent;
0
   
0
   if(EV_ERROR & revents) {
0
- ebb_error("on_client_writable() got error event, closing peer");
0
+ g_message("on_client_writable() got error event, closing peer");
0
     return;
0
   }
0
   
0
   //if(client->written != 0)
0
- // ebb_debug("total written: %d", (int)(client->written));
0
+ // g_debug("total written: %d", (int)(client->written));
0
   
0
   sent = send( client->fd
0
              , client->response_buffer->str + sizeof(gchar)*(client->written)
0
@@ -524,7 +522,7 @@ void on_client_writable(struct ev_loop *loop, ev_io *watcher, int revents)
0
              );
0
   if(sent < 0) {
0
 #ifdef DEBUG
0
- ebb_warning("Error writing: %s", strerror(errno));
0
+ g_message("Error writing: %s", strerror(errno));
0
 #endif
0
     ebb_client_close(client);
0
     return;
0
@@ -532,7 +530,7 @@ void on_client_writable(struct ev_loop *loop, ev_io *watcher, int revents)
0
   client->written += sent;
0
   
0
   assert(client->written <= client->response_buffer->len);
0
- //ebb_info("wrote %d bytes. total: %d", (int)sent, (int)(client->written));
0
+ //g_message("wrote %d bytes. total: %d", (int)sent, (int)(client->written));
0
   
0
   ev_timer_again(loop, &(client->timeout_watcher));
0
   
0
@@ -620,9 +618,9 @@ static int server_socket(const int port) {
0
     
0
     flags = 1;
0
     setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, (void *)&flags, sizeof(flags));
0
- // setsockopt(sfd, SOL_SOCKET, SO_KEEPALIVE, (void *)&flags, sizeof(flags));
0
- // setsockopt(sfd, SOL_SOCKET, SO_LINGER, (void *)&ling, sizeof(ling));
0
- // setsockopt(sfd, IPPROTO_TCP, TCP_NODELAY, (void *)&flags, sizeof(flags));
0
+ setsockopt(sfd, SOL_SOCKET, SO_KEEPALIVE, (void *)&flags, sizeof(flags));
0
+ setsockopt(sfd, SOL_SOCKET, SO_LINGER, (void *)&ling, sizeof(ling));
0
+ setsockopt(sfd, IPPROTO_TCP, TCP_NODELAY, (void *)&flags, sizeof(flags));
0
     
0
     /*
0
      * the memset call clears nonstandard fields in some impementations
0
@@ -701,7 +699,7 @@ static int server_socket_unix(const char *path, int access_mask) {
0
         return -1;
0
     }
0
     umask(old_umask);
0
- if (listen(sfd, 1024) == -1) {
0
+ if (listen(sfd, EBB_MAX_CLIENTS) == -1) {
0
         perror("listen()");
0
         close(sfd);
0
         return -1;
...
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 
 
33
34
35
...
18
19
20
 
 
 
 
 
 
 
 
 
 
 
 
21
22
23
24
25
0
@@ -18,18 +18,8 @@
0
 typedef struct ebb_server ebb_server;
0
 typedef struct ebb_client ebb_client;
0
 
0
-#define EBB_LOG_DOMAIN "Ebb"
0
-#define ebb_error(str, ...) \
0
- g_log(EBB_LOG_DOMAIN, G_LOG_LEVEL_ERROR, str, ## __VA_ARGS__);
0
-#define ebb_warning(str, ...) \
0
- g_log(EBB_LOG_DOMAIN, G_LOG_LEVEL_WARNING, str, ## __VA_ARGS__);
0
-#define ebb_info(str, ...) \
0
- g_log(EBB_LOG_DOMAIN, G_LOG_LEVEL_INFO, str, ## __VA_ARGS__);
0
-#define ebb_debug(str, ...) \
0
- g_log(EBB_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, str, ## __VA_ARGS__);
0
-
0
-#define EBB_BUFFERSIZE (2*1024)
0
-#define EBB_MAX_CLIENTS 200
0
+#define EBB_BUFFERSIZE (40*1024)
0
+#define EBB_MAX_CLIENTS 950
0
 #define EBB_TIMEOUT 30.0
0
 #define EBB_MAX_ENV 100
0
 #define EBB_TCP_COMMON \
...
130
131
132
133
134
135
136
...
130
131
132
 
133
134
135
0
@@ -130,7 +130,6 @@ VALUE server_process_connections(VALUE x, VALUE server)
0
   
0
   Data_Get_Struct(server, ebb_server, _server);
0
   
0
-
0
   ev_timer timeout;
0
   ev_timer_init (&timeout, oneshot_timeout, 0.5, 0.);
0
   ev_timer_start (_server->loop, &timeout);

Comments

    No one has commented yet.