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
ebb_server_listen_on_unix_socket() is working

In the Ruby binding just pass :unix_socket option with a filename to start

Ebb on a AF_UNIX socket.

It includes a very simple unit test. (Should be improved.)
ryah (author)
about 1 month ago
commit  38185f36847ca1315f9241302d6bab7f2f7b1495
tree    0f45e4e6a17cb3e3ee3ac1d4c1cb63199db2d145
parent  8d410a265216bc390fe079ef5655ec33d7970d56
...
77
78
79
80
 
 
81
...
77
78
79
 
80
81
82
0
@@ -77,5 +77,6 @@ end
0
 
0
 if $0 == __FILE__
0
   require DIR + '/../ruby_lib/ebb'
0
- server = Ebb::start_server(SimpleApp.new, :port => 4001)
0
+ server = Ebb::start_server(SimpleApp.new, :unix_socket => '/tmp/ebb.sock')
0
+ #server = Ebb::start_server(SimpleApp.new, :port => 4001)
0
 end
...
483
484
485
486
487
488
489
490
491
492
 
 
493
494
495
...
567
568
569
570
 
571
 
572
573
574
...
585
586
587
588
 
589
590
591
...
483
484
485
 
 
486
487
488
489
490
491
492
493
494
495
...
567
568
569
 
570
571
572
573
574
575
...
586
587
588
 
589
590
591
592
0
@@ -483,13 +483,13 @@ void ebb_server_unlisten(ebb_server *server)
0
 
0
 int ebb_server_listen_on_fd(ebb_server *server, const int sfd)
0
 {
0
- set_nonblock(sfd);
0
-
0
   if (listen(sfd, EBB_MAX_CLIENTS) < 0) {
0
     perror("listen()");
0
     return -1;
0
   }
0
   
0
+ set_nonblock(sfd); /* XXX: superfluous? */
0
+
0
   server->fd = sfd;
0
   assert(server->port == NULL);
0
   assert(server->socketpath == NULL);
0
@@ -567,8 +567,9 @@ int ebb_server_listen_on_unix_socket(ebb_server *server, const char *socketpath)
0
   }
0
   
0
   /* Clean up a previous socket file if we left it around */
0
- if(lstat(socketpath, &tstat) == 0 && S_ISSOCK(tstat.st_mode))
0
+ if(lstat(socketpath, &tstat) == 0 && S_ISSOCK(tstat.st_mode)) {
0
     unlink(socketpath);
0
+ }
0
   
0
   flags = 1;
0
   setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, (void *)&flags, sizeof(flags));
0
@@ -585,7 +586,7 @@ int ebb_server_listen_on_unix_socket(ebb_server *server, const char *socketpath)
0
   strcpy(addr.sun_path, socketpath);
0
   old_umask = umask( ~(access_mask & 0777) );
0
   
0
- if( bind(sfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
0
+ if(bind(sfd, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
0
     perror("bind()");
0
     goto error;
0
   }
...
101
102
103
104
 
105
106
 
107
108
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
111
112
113
114
115
 
116
117
118
...
101
102
103
 
104
105
 
106
107
108
 
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
 
129
130
131
132
0
@@ -101,18 +101,32 @@ end
0
 class ServerTestSocket < ServerTest
0
   def get(path)
0
     socket = UNIXSocket.open(@socketfile)
0
- socket.write("GET #{path} HTTP/1.0\r\n")
0
+ socket.write("GET #{path} HTTP/1.0\r\n\r\n")
0
     response = ""
0
- while chunk = socket.recv(100)
0
+ while chunk = socket.read(100)
0
       response << chunk
0
     end
0
- env = JSON.parse(response)
0
+ body = response.split("\r\n\r\n")[1]
0
+ env = JSON.parse(body)
0
+ ensure
0
+ socket.close if socket
0
+ end
0
+
0
+ def post(path, data)
0
+ socket = UNIXSocket.open(@socketfile)
0
+ socket.write("POST #{path} HTTP/1.0\r\nContent-Length: #{data.length}\r\n\r\n#{data}")
0
+ response = ""
0
+ while chunk = socket.read(100)
0
+ response << chunk
0
+ end
0
+ body = response.split("\r\n\r\n")[1]
0
+ env = JSON.parse(body)
0
   ensure
0
     socket.close if socket
0
   end
0
   
0
   def setup
0
- @socketfile = '/tmp/ebb_socket.sock'
0
+ @socketfile = '/tmp/ebb_unittest.sock'
0
     Thread.new { Ebb.start_server(HelperApp.new, :unix_socket => @socketfile) }
0
     sleep 0.1 until Ebb.running?
0
   end

Comments

    No one has commented yet.