Just another update
This commit is contained in:
parent
a25938f123
commit
00a190b0a6
6591 changed files with 94363 additions and 23227 deletions
27
Task/Chat-server/Haskell/chat-server-2.hs
Normal file
27
Task/Chat-server/Haskell/chat-server-2.hs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
global mlck, nCons, cons
|
||||
|
||||
procedure main()
|
||||
mlck := mutex()
|
||||
nCons := 0
|
||||
cons := mutex(set())
|
||||
while f := open(":12321","na") do {
|
||||
handle_client(f)
|
||||
critical mlck: if nCons <= 0 then close(f)
|
||||
}
|
||||
end
|
||||
|
||||
procedure handle_client(f)
|
||||
critical mlck: nCons +:= 1
|
||||
thread {
|
||||
select(f,1000) & {
|
||||
writes(f, "Name? ")
|
||||
nick := (read(f) ? tab(upto('\n\r')))
|
||||
every write(!cons, nick," has joined.")
|
||||
insert(cons, f)
|
||||
while s := read(f) do every write(!cons, nick,": ",s)
|
||||
}
|
||||
delete(cons, f)
|
||||
every write(!cons, nick," has left.")
|
||||
critical mlck: nCons -:= 1
|
||||
}
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue