2018-12-11 03:15:54 -08:00
|
|
|
//
|
|
|
|
// Created by onekopaka on 12/8/18.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <memory.h>
|
|
|
|
#include "irc.h"
|
|
|
|
|
2018-12-11 03:40:00 -08:00
|
|
|
irc::irc(PRFileDesc* fileDesc, std::string netName, ui* uiInstance) {
|
2018-12-11 03:15:54 -08:00
|
|
|
this->fd = fileDesc;
|
2018-12-11 03:40:00 -08:00
|
|
|
this->netName = netName;
|
2018-12-11 03:15:54 -08:00
|
|
|
this->uiInst = uiInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
void irc::run() {
|
|
|
|
PRPollDesc pollDesc;
|
|
|
|
pollDesc.fd = this->fd;
|
|
|
|
pollDesc.in_flags = PR_POLL_READ | PR_POLL_WRITE | PR_POLL_EXCEPT;
|
|
|
|
pollDesc.out_flags = 0;
|
|
|
|
|
|
|
|
PRInt32 result = PR_Poll(&pollDesc, 1, PR_INTERVAL_NO_TIMEOUT);
|
|
|
|
while(result != -1) {
|
|
|
|
if(result > 0) {
|
|
|
|
if(pollDesc.out_flags & PR_POLL_READ) {
|
|
|
|
char* buf = new char[1024];
|
|
|
|
PRInt32 bytesRead = PR_Read(this->fd, buf, 1024);
|
|
|
|
uiInst->mainLog->appendPlainText(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = PR_Poll(&pollDesc, 1, PR_INTERVAL_NO_TIMEOUT);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|