<mrvn>
My code listens on a socket. After its killed the socket stays blocked for a minute or two.
<karryall>
there's a timeout
<karryall>
that's an OS thing
<mrvn>
Yes. But one can set that somehow.
<karryall>
(btw use Unix.handle_unix_error to get prettier error messages)
<mrvn>
I already use (Unix.error_message error)
<mrvn>
Does that give differen messages than handle_unix_error?
<karryall>
no, handle_unix_error use error_message
<karryall>
the point is that you do not get Unix.Unix_error(50,
<karryall>
but something clearer than 50 (like "EADDRINUSE" or smthg)
<mrvn>
50 is what Unix.error_message error returns
<mrvn>
UnixIO.raw_read: Unix.Unix_error(Transport endpoint is not connected, read, )
<mrvn>
Thats what I get for other errors.
<mrvn>
Dunno why it says 50 for the bind error.
<karryall>
weird
<mrvn>
| SO_REUSEADDR (*Allow reuse of local addresses for bind*)
<mrvn>
Shoudln't setting that true prevent the bind failure?
<det>
I dont think so
<det>
I've had the same problem with python
<det>
and SO_RESUEADDR didnt fix it
<det>
#twisted would be a good place to ask :)
<det>
I think you probally arent shuting own the socket properly ?
<mrvn>
The prog gets killed. Nothing gets closed.
<karryall>
then trap the signal and shutdown properly
<karryall>
there's the SO_LINGER socket option also
<mrvn>
karryall: Can I hook into the destructor of the GC for that instead of traping the signal?
systems has quit [Read error: 110 (Connection timed out)]
<karryall>
mrvn: not good, it is not guaranteed that the GC will run the finalizer
<det>
mrvn, how does the program get killed ?
<mrvn>
is there an "at_exit" that gets called on ctrl-c?
<det>
oh :)
<det>
ctrl-c sends some signal
<det>
SIGINT, I believe
<mrvn>
UnixIO.make_server: Unix.Unix_error(Address already in use, bind, )
<mrvn>
Thats better. I forgot to catch the exception.
<det>
<Kenzie>
<det>
oopds
<det>
exception Break
<det>
Exception raised on interactive interrupt if Sys.catch_break is on.
<karryall>
good solution : at_exit functions are executed in case of uncaught exceptions
<det>
Sys.catch_break true
<det>
oh, you got it
<mrvn>
karryall: that sound good. I plan to catch signals somewhere else thats not yet ready.
wrunt has joined #ocaml
<mrvn>
karryall: I can only have one at_exit function, right?
<karryall>
no, you can register several
<mrvn>
karryall: and how do I remove one?
<karryall>
you can't
<mrvn>
thought so. So I better add one function that then handles all remaining open file_descr.
<det>
Can't you just be sure to catch all exceptions ?
<mrvn>
at_exit isn't called on unhandled signals.
<mrvn>
det: and then what? If the server can't get the port the only thing he could do is retry in a minute.
docelic|sleepo is now known as docelic
<det>
Is it possible for a module to reference itself ?
<mrvn>
Sure.
<mrvn>
Why shouldn't it?
<det>
for instance, a Circle module could define a submodule by passing itself to a functor ?
<mrvn>
Hah, got it. I have to set SO_REUSEADDR _before_ bind.
<det>
If you properly shutdown the socket, be it by using at_exit, catching Break, or whatever, the port should always be available
<mrvn>
no.
<mrvn>
Its a security feature so that one can#t shutdown a service and take over its port before other tools can notice the change.
<det>
oohh
<det>
and SO_REUSEADDR negates this "feature" ?
<mrvn>
yep
<mrvn>
But only if you set it before binding the socket.
olrion has joined #ocaml
<det>
even if you Unix.shutdown ?
<det>
it will not be bindable ?
<det>
or close it rather
<mrvn>
Nope. It will remain blocked for about a minute
<mrvn>
I'm doing asynchronous IO and I have a function that finalises a bunch of read requests and waits for them to complete. Its like flush but for input. What would you call it?
<det>
plunge ?
<det>
:p
<mrvn>
it works, it works.
<mrvn>
Does anyone want to implement the http protocoll for me?
<mrvn>
I have asyncrhonous IO and sockets working already.
det has quit ["Hey! Where'd my controlling terminal go?"]
<vegai>
what are you doing, ocaml-twisted? =)
det has joined #ocaml
<mrvn>
Writeing a Bittorrent clone.
<karryall>
mldonkey does it already I think
<vegai>
yup, though it does a lot of other things as well
<mrvn>
Not sure how finished that is
<vegai>
more finished than your program, I guess =)
<karryall>
never tried
<mrvn>
Also mldonkey has a somewhat strange idea on how to limit bandwith.
<mrvn>
Never uses the values given. its allways off.
<docelic>
mrvn, no , download limit is 4x the upload limit you set
<docelic>
unless you leave it at 0, and it uses 0/0 limit
<mrvn>
If I set upload limit of 4 mldonkey says it uses 2.5, my net says its using 5.
<docelic>
hm.. here it works accurately
<mrvn>
Just for bittorrent or are you using donkey2k too?
<vegai>
docelic: I think that's a limitation of the donkey network rather than of mldonkeyu
<det>
tcp connections can always block
<mrvn>
det: Doesn't mean your program should too.
<det>
right.
<det>
I meant, you can always limit download bandwidth, reguardless of the limitations of the network, even if that means ignoring a socket that select tells you is ready for reading
<mrvn>
I have read functions that return a closure (unit -> value) for each read. When you read enough (like a complete structure) you call "finalize_read (fun io -> do_something_with_the_read_values)". finalize_read returns immidiatly and calls the closure later when the pre read values actually arrived.
<mrvn>
det: Actally you can#t limit download bandwith. You can just stop reading it and throw it away and hope the sender catches it and slows down. :(
<det>
yes, TCP will handle all that, right ?
<mrvn>
more or less.
<det>
resending dropped packets, slowing down
<mrvn>
They invented ECN to better handle it but a lot of OS don't support it yet.
<mrvn>
With ECN you can tell the sender "Normaly I would have droped this packet because your sewnding too fast. I got it now but slow down"
<det>
erm, how do you declare a object value to be mutable ?
<mrvn>
val mutable bla = 1
<det>
thanks
<det>
any idea why vec2 is unbound?
<det>
class vec2 x y = object
<det>
val mutable x = x
<det>
val mutable y = y
<det>
method inc x2 y2 = x <- x + x2; y <- y + y2
<det>
end;;
<det>
let v = new vec2 0 0 in
<det>
for i = 0 to 1000000 do
<det>
vec2#inc 1 2
<det>
done;
<det>
oops
<det>
im stupid
<det>
the compiler gives you line #'s for a reason :)
<det>
let v = {x=0; y=0} in
<det>
why is that a syntax error after the }
<det>
got it
cDlm_ has joined #ocaml
cDlm has quit [Killed (NickServ (Ghost: cDlm_!cdlm@lns-th2-11-82-64-173-168.adsl.proxad.net))]
cDlm_ is now known as cDlm
<det>
erm, how can I chain imperative actions ?
<det>
is there something like begin ?
<det>
ok, I answered all my own questions, time to leave you alone :)
det has quit ["*boom*"]
Smerdyakov has joined #ocaml
lus|wazze has joined #ocaml
polin8 has quit [Remote closed the connection]
systems has joined #ocaml
systems has quit ["Client Exiting"]
karryall has quit [Remote closed the connection]
<mrvn>
Anyone written interfaces for C function?
<mrvn>
How do I write a function void foo(void)? Thats type unit -> unit in caml. Can I just call foo or do I need a stub discarding the unit?
<vegai>
well...
<vegai>
# let a () = ();;
<vegai>
val a : unit -> unit = <fun>
<vegai>
# a;;
<vegai>
- : unit -> unit = <fun>
<mrvn>
vegai: no, external init : unit -> int = "OpenSSL_init"
<mrvn>
more like that
<vegai>
ah
<mrvn>
ore rather unit->unit since it allways returns 1.
<vegai>
I'd say you should experiment =)
<mrvn>
CAMLprim value OpenSSL_init(value unit) {
<mrvn>
SSL_library_init();
<mrvn>
return Val_unit;
<mrvn>
}
<mrvn>
Thats what I'm trying now.
<vegai>
read the chapter about this in O'reilly's book?
<mrvn>
whats the url again?
<vegai>
google should find it
mattam_ has joined #ocaml
<mrvn>
Semms to work already. :)
mattam has quit [Read error: 110 (Connection timed out)]
<mrvn>
Now if I only knew what functions from OpenSSL I need next.
Smerdyakov has quit ["because"]
Smerdyakov has joined #ocaml
cDlm_ has joined #ocaml
docelic has quit ["l8888r"]
mrvn_ has joined #ocaml
olrion has quit [Read error: 54 (Connection reset by peer)]
olrion has joined #ocaml
mrvn has quit [Read error: 60 (Operation timed out)]
mrvn_ is now known as mrvn
cDlm has quit [Connection timed out]
foxster has quit []
olrion has quit [Remote closed the connection]
karryall has joined #ocaml
TachYon has joined #ocaml
TachYon76 has joined #ocaml
cDlm_ is now known as cDlm
lus|wazze has quit ["Quidquid latine dictum sit, altum sonatur."]
lus|wazze has joined #ocaml
whee has joined #ocaml
TachYon76 has quit ["Client Exiting"]
Smerdyakov has quit ["eat"]
docelic has joined #ocaml
docelic has quit ["sure deal joy :"]
amitm has joined #ocaml
TachYon has quit ["Client Exiting"]
amitm has quit ["Leaving"]
mattam has joined #ocaml
mattam_ has quit [Read error: 60 (Operation timed out)]
mattam_ has joined #ocaml
docelic has joined #ocaml
mattam has quit [Read error: 60 (Operation timed out)]
mrvn has quit [asimov.freenode.net irc.freenode.net]
wrunt has quit [asimov.freenode.net irc.freenode.net]
gl has quit [asimov.freenode.net irc.freenode.net]
wrunt has joined #ocaml
Smerdyakov has joined #ocaml
mrvn has joined #ocaml
mattam_ has quit [Read error: 110 (Connection timed out)]