Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: b21537fe41
Fetching contributors…

Cannot retrieve contributors at this time

file 29 lines (23 sloc) 0.981 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
module Io : Irc_transport.IO = struct
  type 'a t = 'a Lwt.t
  let (>>=) = Lwt.bind
  let return = Lwt.return

  type file_descr = Lwt_unix.file_descr

  let open_socket server port =
    let sock = Lwt_unix.socket Lwt_unix.PF_INET Lwt_unix.SOCK_STREAM 0 in
    let addr = Lwt_unix.ADDR_INET (Unix.inet_addr_of_string server, port) in
    lwt () = Lwt_unix.connect sock addr in
    return sock

  let close_socket = Lwt_unix.close

  let rec buffered_read fd str offset length =
    if length = 0 then return () else
      lwt chars_read = Lwt_unix.read fd str offset length in
      if chars_read = 0
      then Lwt.fail End_of_file
      else buffered_read fd str (offset + chars_read) (length - chars_read)

  let rec buffered_write fd str offset length =
    if length = 0 then return () else
      lwt chars_written = Lwt_unix.write fd str offset length in
      buffered_write fd str (offset + chars_written) (length - chars_written)
end

module Client = Irc_client.Make(Io)
Something went wrong with that request. Please try again.