Fixed buf in Client.handle_input

F it, I'll just use regular expressions (Str.split).  They're easier to code,
the code looks cleaner, and it fixes a buf with a case I hadn't considered.
This commit is contained in:
Neale Pickett 2008-02-29 17:16:00 -07:00
parent 1617dbca19
commit 1b517745bb
2 changed files with 22 additions and 20 deletions

View File

@ -3,6 +3,9 @@ OCAMLPACKS[] =
equeue
pcre
str
NATIVE_ENABLED = true
BYTE_ENABLED = true
OCAMLCFLAGS += -g
.DEFAULT: ircd
@ -11,9 +14,11 @@ OCamlProgram(ircd, ircd irc command client channel)
section
OCAMLPACKS[] +=
oUnit
NATIVE_ENABLED = false
tests.cmx:
tests.cmi:
tests.cmo:
tests$(EXT_OBJ):
OCamlProgram(tests, tests chat ircd irc command client channel)

View File

@ -73,26 +73,23 @@ let handle_command_login cli cmd =
"NOTICE"
[nick]))
let rec handle_input cli =
match cli.ibuf with
| "" ->
()
| ibuf ->
let p =
let nlp = String.index ibuf '\n' in
if ((String.get ibuf (nlp - 1)) = '\r') then
(nlp - 1)
else
nlp
in
let s = String.sub ibuf 0 p in
if p >= !(cli.ibuf_len) then
raise Not_found;
cli.ibuf_len := !(cli.ibuf_len) - (p + 1);
String.blit ibuf (p + 1) ibuf 0 !(cli.ibuf_len);
let parsed = Command.from_string s in
cli.handle_command cli parsed;
handle_input cli
let crlf = Str.regexp "\r?\n"
let handle_input cli =
let buf = Str.string_before cli.ibuf !(cli.ibuf_len) in
let lines = Str.split crlf buf in
let rec loop l =
match l with
| [] ->
()
| [leftover] ->
String.blit leftover 0 cli.ibuf 0 (String.length leftover)
| line :: tl ->
let parsed = Command.from_string line in
cli.handle_command cli parsed;
loop tl
in
loop lines
let handle_event ues esys e =
match e with