Skip to content
This repository
Browse code

[GH #898] Fix HTTP;Daemon, add to Makefile

Not yet ready, one string op wrong
  • Loading branch information...
commit 89107f0e6e3493e789dce9418b18618f2c920829 1 parent 7306645
Reini Urban authored
1  config/gen/makefiles/root.in
@@ -280,6 +280,7 @@ GEN_LIBRARY = \
280 280
 	$(LIBRARY_DIR)/yaml_dumper.pbc \
281 281
 	$(LIBRARY_DIR)/YAML/Tiny.pbc \
282 282
 	$(LIBRARY_DIR)/Getopt/Obj.pbc \
  283
+	$(LIBRARY_DIR)/HTTP/Daemon.pbc \
283 284
 	$(LIBRARY_DIR)/HTTP/Message.pbc \
284 285
 	$(LIBRARY_DIR)/Iter.pbc \
285 286
 	$(LIBRARY_DIR)/JSON.pbc \
49  runtime/parrot/library/HTTP/Daemon.pir
@@ -84,7 +84,11 @@ at the pio.
84 84
 .const string CRCR     = "\r\r"
85 85
 
86 86
 .include "stat.pasm"
87  
-.include 'io_thr_msg.pasm'
  87
+.include 'except_types.pasm'
  88
+.include 'socket.pasm'
  89
+
  90
+.loadlib 'io_ops'
  91
+.loadlib 'sys_ops'
88 92
 
89 93
 =back
90 94
 
@@ -133,30 +137,31 @@ Redirect to and serve files from F<docs/html>.
133 137
     $P0 = '.'
134 138
     setattribute self, 'doc_root', $P0
135 139
 
136  
-    # create socket
137  
-    .local pmc sock
138  
-    sock = socket 2, 1, 6 	# PF_INET, SOCK_STREAM, tcp
139  
-    unless sock goto err_sock
140  
-    setattribute self, 'socket', sock
  140
+    # create listener socket
  141
+    .local pmc listener
  142
+    listener = new 'Socket'
  143
+    listener.'socket'(.PIO_PF_INET, .PIO_SOCK_STREAM, .PIO_PROTO_TCP)
  144
+    unless listener goto err_sock
  145
+    setattribute self, 'socket', listener
141 146
 
142 147
     .local int port
143  
-    .local string adr
  148
+    .local string host
  149
+    host = args['LocalAddr']
144 150
     port = args['LocalPort']
145  
-    adr = args['LocalAddr']
146 151
 
147 152
     # bind
148 153
     .local string i_addr
149 154
     .local int res
150  
-    i_addr = sockaddr port, adr
151  
-    res = bind sock, i_addr
  155
+    i_addr = listener.'sockaddr'(host, port)
  156
+    res = listener.'bind'(i_addr)
152 157
     if res == -1 goto err_bind
153 158
 
154 159
     # listen
155  
-    res = listen sock, 1
  160
+    res = listener.'listen'(1)
156 161
     if res == -1 goto err_listen
157 162
 
158 163
     # add connection
159  
-    self.'new_conn'(sock)
  164
+    self.'new_conn'(listener)
160 165
     .return()
161 166
 
162 167
 err_listen:
@@ -165,7 +170,7 @@ err_bind:
165 170
     err $S0, $I0
166 171
     printerr $S0
167 172
     printerr "\n"
168  
-    close sock
  173
+    listener.'close'()
169 174
 err_sock:
170 175
     $P0 = new 'Undef'
171 176
     setattribute self, 'socket', $P0
@@ -298,7 +303,7 @@ Concat passed arguments and schedule the string for logging.
298 303
     n += 3
299 304
     now = time
300 305
     $S0 = gmtime now
301  
-    chopn $S0, 1	# XXX why 1? asctime is \n terminated
  306
+    $S0 = chopn $S0, 1	# XXX why 1? asctime is \n terminated
302 307
     unshift args, ", "
303 308
     unshift args, $S0
304 309
     push args, "\n"
@@ -340,7 +345,7 @@ add_lp:
340 345
 =item _del_stale_conns()
341 346
 
342 347
 Not yet used method to delete old connections for the active set.
343  
-Called from server runnloop.
  348
+Called from server runloop.
344 349
 
345 350
 =cut
346 351
 
@@ -387,7 +392,7 @@ Return true, if the given connection is already active.
387 392
 
388 393
 =cut
389 394
 
390  
-# add coket to active connections
  395
+# add socket to active connections
391 396
 .sub 'new_conn' :method
392 397
     .param pmc sock
393 398
     .local pmc active, conn
@@ -402,7 +407,7 @@ Return true, if the given connection is already active.
402 407
 .sub 'accept_conn' :method
403 408
     .local pmc orig, work
404 409
     orig   = getattribute self, 'socket'
405  
-    accept work, orig
  410
+    work.'accept'(orig)
406 411
     self.'new_conn'(work)
407 412
 .end
408 413
 
@@ -413,7 +418,7 @@ Return true, if the given connection is already active.
413 418
     .local pmc active, orig, sock
414 419
     .local int i, n
415 420
     sock = getattribute work, 'socket'
416  
-    close sock
  421
+    sock.'close'()
417 422
     active = getattribute self, 'active'
418 423
 loop:
419 424
     n = elements active
@@ -605,13 +610,13 @@ Internal method to read from the client. It returns a request string.
605 610
     # check method, read Content-Length if needed and read
606 611
     # until message is complete
607 612
 MORE:
608  
-    res = recv sock, buf
  613
+    res = sock.'recv'(buf)
609 614
     srv.'debug'("**read ", res, " bytes\n")
610 615
     if res > 0 goto not_empty
611 616
     do_close = 1
612 617
     if res <= 0 goto done
613 618
 not_empty:
614  
-    concat req, buf
  619
+    req = concat req, buf
615 620
     index pos, req, CRLFCRLF
616 621
     if pos >= 0 goto have_hdr
617 622
     index pos, req, LFLF
@@ -649,7 +654,7 @@ CGI invocation.
649 654
     .local pmc sock
650 655
     sock = self.'socket'()
651 656
     rep = resp.'as_string'()
652  
-    $I0 = send sock, rep	# XXX don't ignore
  657
+    $I0 = sock.'send'(rep)	# XXX don't ignore
653 658
 .end
654 659
 
655 660
 .sub 'send_file_response' :method
@@ -811,7 +816,7 @@ START:
811 816
     inc pos_in
812 817
 
813 818
 INC_IN:
814  
-    concat out, char_out
  819
+    out = concat out, char_out
815 820
     inc pos_in
816 821
     goto START
817 822
 END:

0 notes on commit 89107f0

Please sign in to comment.
Something went wrong with that request. Please try again.