Created
November 6, 2011 13:36
-
-
Save pdonadeo/1342885 to your computer and use it in GitHub Desktop.
Source to reproduce a possible bug in BatEnum.lines_of
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* COMPILE WITH: | |
* ocamlfind ocamlc -g -linkpkg -package batteries broken_client.ml -o client *) | |
let in_, out_ = BatUnix.open_connection (Unix.ADDR_UNIX "my_socket");; | |
BatEnum.fold | |
(fun count l -> Printf.printf "%s\n%!" l; count + 1) | |
1 | |
(BatIO.lines_of in_) | |
;; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- coding: utf-8 -*- | |
import socket,os | |
def create_connection(socket_name): | |
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) | |
try: | |
os.remove(socket_name) | |
except OSError: | |
pass | |
s.bind(socket_name) | |
s.listen(1) | |
conn, addr = s.accept() | |
return s, conn | |
socket_name = os.path.join(os.getcwd(), 'my_socket') | |
s, conn = create_connection(socket_name) | |
for i, l in enumerate(open('mail.log').readlines()): | |
l = l.strip() | |
try: | |
conn.send(l) | |
conn.send('\n') | |
print 'line number %d SENT' % (i + 1) | |
except IOError as (errno, strerror): | |
s.shutdown(socket.SHUT_RDWR) | |
s.close() | |
s, conn = create_connection(socket_name) | |
conn.send(l) | |
conn.send('\n') | |
print 'line number %d SENT' % (i + 1) | |
conn.close() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* COMPILE WITH: | |
* ocamlfind ocamlc -g -linkpkg -package batteries working_client.ml -o client *) | |
open BatIO;; | |
let lines_of in_ = | |
BatEnum.make | |
~next:(fun () -> | |
try input_line in_ | |
with End_of_file -> raise BatEnum.No_more_elements) | |
~count:(fun () -> raise BatEnum.Infinite_enum) | |
~clone:(fun () -> failwith "This enumeration cannot be cloned!") | |
;; | |
let in_, out_ = Unix.open_connection (Unix.ADDR_UNIX "my_socket");; | |
BatEnum.fold | |
(fun count l -> Printf.printf "%s\n%!" l; count + 1) | |
1 | |
(lines_of in_) | |
;; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment