2 ** Copyright 2002, Travis Geiselbrecht. All rights reserved.
3 ** Distributed under the terms of the NewOS License.
5 #include <sys/syscalls.h>
8 #include <socket/socket.h>
10 #include "ircreader.h"
11 #include "ircengine.h"
13 IRCReader::IRCReader(int socket
, IRCEngine
*engine
)
21 IRCReader::~IRCReader()
23 // forgive me father...
24 if(mReaderThread
>= 0)
25 _kern_thread_kill_thread(mReaderThread
);
28 int IRCReader::Start()
30 mReaderThread
= _kern_thread_create_thread("irc reader", &ThreadEntry
, (void *)this);
34 _kern_thread_resume_thread(mReaderThread
);
43 ssize_t bytes_received
;
45 bytes_received
= read(mSocket
, buf
, sizeof(buf
));
46 if(bytes_received
< 0) {
47 mEngine
->SocketError(bytes_received
);
51 // add this data to the end of the line buffer we have
52 for(int i
= 0; i
< bytes_received
; i
++) {
53 mBuf
[mBufPos
++] = buf
[i
];
54 if(mBufPos
== sizeof(mBuf
) - 1 || buf
[i
] == '\n') {
56 mEngine
->ReceivedSocketData(mBuf
, mBufPos
);
64 int IRCReader::ThreadEntry(void *args
)
66 IRCReader
*reader
= (IRCReader
*)args
;