Some work - trying to catch up to where I was.
This commit is contained in:
parent
96e73d6341
commit
e0c0e2c07e
53
Socket.cpp
53
Socket.cpp
@ -68,44 +68,44 @@ namespace core
|
|||||||
void Socket::onUnregistered() {}
|
void Socket::onUnregistered() {}
|
||||||
|
|
||||||
bool Socket::eventReceived(struct epoll_event event, long long eventId) {
|
bool Socket::eventReceived(struct epoll_event event, long long eventId) {
|
||||||
// coreutils::Log(coreutils::LOG_DEBUG_1) << "Event process beginning for socket " << getDescriptor();
|
coreutils::Log(coreutils::LOG_DEBUG_1) << "Event process beginning for socket " << getDescriptor();
|
||||||
if(inHandler)
|
if(inHandler)
|
||||||
// coreutils::Log(coreutils::LOG_DEBUG_2) << "inHandler was already true.";
|
coreutils::Log(coreutils::LOG_DEBUG_2) << "inHandler was already true.";
|
||||||
inHandler = true;
|
inHandler = true;
|
||||||
if(event.events & EPOLLRDHUP) {
|
if(event.events & EPOLLRDHUP) {
|
||||||
// coreutils::Log(coreutils::LOG_DEBUG_2) << "EPOLLRDHUP";
|
coreutils::Log(coreutils::LOG_DEBUG_2) << "EPOLLRDHUP";
|
||||||
readHangup = true;
|
readHangup = true;
|
||||||
shutdown("hangup received");
|
shutdown("hangup received");
|
||||||
}
|
}
|
||||||
if(event.events & EPOLLIN) {
|
if(event.events & EPOLLIN) {
|
||||||
// coreutils::Log(coreutils::LOG_DEBUG_2) << "EPOLLIN";
|
coreutils::Log(coreutils::LOG_DEBUG_2) << "EPOLLIN";
|
||||||
coreutils::ZString zbuffer(buffer, length);
|
coreutils::ZString zbuffer(buffer, length);
|
||||||
lock.lock();
|
lock.lock();
|
||||||
receiveData(zbuffer);
|
receiveData(zbuffer);
|
||||||
if(!shutDown) {
|
if(!shutDown) {
|
||||||
inHandler = false;
|
inHandler = false;
|
||||||
lock.unlock();
|
lock.unlock();
|
||||||
resetSocket();
|
resetSocket();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(event.events & EPOLLWRNORM) {
|
if(event.events & EPOLLWRNORM) {
|
||||||
// coreutils::Log(coreutils::LOG_DEBUG_2) << "EPOLLWRNORM";
|
coreutils::Log(coreutils::LOG_DEBUG_2) << "EPOLLWRNORM";
|
||||||
writeSocket();
|
writeSocket();
|
||||||
inHandler = false;
|
inHandler = false;
|
||||||
resetSocket();
|
resetSocket();
|
||||||
}
|
}
|
||||||
inHandler = false;
|
inHandler = false;
|
||||||
// coreutils::Log(coreutils::LOG_DEBUG_1) << "Event process ending for socket " << getDescriptor();
|
coreutils::Log(coreutils::LOG_DEBUG_1) << "Event process ending for socket " << getDescriptor();
|
||||||
return !shutDown;
|
return !shutDown;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::onDataReceived(std::string data)
|
void Socket::connectionRequest() {}
|
||||||
{
|
|
||||||
|
void Socket::onDataReceived(std::string data) {
|
||||||
throw coreutils::Exception("Need to override onDataReceived.", __FILE__, __LINE__, -1);
|
throw coreutils::Exception("Need to override onDataReceived.", __FILE__, __LINE__, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::onDataReceived(coreutils::ZString &data)
|
void Socket::onDataReceived(coreutils::ZString &data) {
|
||||||
{
|
|
||||||
onDataReceived(std::string(data.getData(), data.getLength()));
|
onDataReceived(std::string(data.getData(), data.getLength()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,28 +117,23 @@ namespace core
|
|||||||
int error = -1;
|
int error = -1;
|
||||||
if((len = ::read(getDescriptor(), buffer.getData(), buffer.getLength())) >= 0) {
|
if((len = ::read(getDescriptor(), buffer.getData(), buffer.getLength())) >= 0) {
|
||||||
coreutils::ZString zbuffer(buffer.getData(), len);
|
coreutils::ZString zbuffer(buffer.getData(), len);
|
||||||
// coreutils::Log(coreutils::LOG_DEBUG_1) << zbuffer;
|
// coreutils::Log(coreutils::LOG_DEBUG_1) << zbuffer;
|
||||||
onDataReceived(zbuffer);
|
onDataReceived(zbuffer);
|
||||||
}
|
} else {
|
||||||
else
|
error = errno;
|
||||||
{
|
switch (error) {
|
||||||
|
|
||||||
error = errno;
|
|
||||||
|
|
||||||
switch (error)
|
|
||||||
{
|
|
||||||
|
|
||||||
// When a listening socket receives a connection
|
// When a listening socket receives a connection
|
||||||
// request we get one of these.
|
// request we get one of these.
|
||||||
//
|
|
||||||
case ENOTCONN:
|
case ENOTCONN:
|
||||||
onDataReceived(blank);
|
connectionRequest();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ECONNRESET:
|
case ECONNRESET:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw coreutils::Exception("Error in read of data from socket.", __FILE__, __LINE__, error);
|
throw coreutils::Exception("Error in read of data from socket.", __FILE__, __LINE__, error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -146,7 +141,7 @@ namespace core
|
|||||||
|
|
||||||
void Socket::writeSocket() {
|
void Socket::writeSocket() {
|
||||||
outlock.lock();
|
outlock.lock();
|
||||||
// coreutils::Log(coreutils::LOG_DEBUG_3) << "writing data to socket " << getDescriptor();
|
// coreutils::Log(coreutils::LOG_DEBUG_3) << "writing data to socket " << getDescriptor();
|
||||||
if(fifo.size() > 0) {
|
if(fifo.size() > 0) {
|
||||||
if(!shutDown)
|
if(!shutDown)
|
||||||
int rc = ::write(descriptor, fifo.front().c_str(), fifo.front().length());
|
int rc = ::write(descriptor, fifo.front().c_str(), fifo.front().length());
|
||||||
|
7
Socket.h
7
Socket.h
@ -137,6 +137,13 @@ namespace core {
|
|||||||
|
|
||||||
// virtual void onConnected(); ///< Called when socket is open and ready to communicate.
|
// virtual void onConnected(); ///< Called when socket is open and ready to communicate.
|
||||||
|
|
||||||
|
///
|
||||||
|
/// The connectionRequest method is called to instantiate a new session handler object
|
||||||
|
/// and form a new connection to a listening server.
|
||||||
|
///
|
||||||
|
|
||||||
|
virtual void connectionRequest();
|
||||||
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
|
@ -25,7 +25,8 @@ namespace core {
|
|||||||
close(getDescriptor());
|
close(getDescriptor());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TCPServer::onDataReceived(std::string data) {
|
void TCPServer::connectionRequest() {
|
||||||
|
coreutils::Log(coreutils::LOG_DEBUG_2) << "Connection request is being received on socket " << getDescriptor() << ".";
|
||||||
lock.lock();
|
lock.lock();
|
||||||
TCPSession *session = accept();
|
TCPSession *session = accept();
|
||||||
if (session)
|
if (session)
|
||||||
|
11
TCPServer.h
11
TCPServer.h
@ -125,16 +125,11 @@ namespace core {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
///
|
///
|
||||||
/// Override the virtual dataReceived since for the server these
|
/// This method is called by the lower socket when a connection request comes into
|
||||||
/// are requests to accept the new connection socket.
|
/// the listening and bound server port.
|
||||||
/// No data is to be read or written when this method is called. It is the response to
|
|
||||||
/// the fact that a new connection is coming into the system
|
|
||||||
///
|
|
||||||
/// @param data the pointer to the buffer containing the received data.
|
|
||||||
/// @param length the length of the associated data buffer.
|
|
||||||
///
|
///
|
||||||
|
|
||||||
void onDataReceived(std::string data) override;
|
void connectionRequest() override;
|
||||||
|
|
||||||
///
|
///
|
||||||
/// This method is called when the Command associated with this object is requested
|
/// This method is called when the Command associated with this object is requested
|
||||||
|
Binary file not shown.
@ -17,7 +17,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
core::EPoll ePoll;
|
core::EPoll ePoll;
|
||||||
|
|
||||||
core::ConsoleServer console(ePoll, core::IPAddress(ipAddress, 1027));
|
core::TCPServer console(ePoll, core::IPAddress(ipAddress, 1027));
|
||||||
|
|
||||||
console.commands.add(ePoll, "threads");
|
console.commands.add(ePoll, "threads");
|
||||||
console.commands.add(console, "consoles");
|
console.commands.add(console, "consoles");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user