diff --git a/.gitignore b/.gitignore index 49dca78..546c058 100644 --- a/.gitignore +++ b/.gitignore @@ -10,5 +10,5 @@ docs/html */*.ipch */mmap_address.bin .history/* -html -latex \ No newline at end of file +html/* +latex/* \ No newline at end of file diff --git a/Socket.cpp b/Socket.cpp index 18fd397..f3e724d 100644 --- a/Socket.cpp +++ b/Socket.cpp @@ -148,7 +148,7 @@ namespace core outlock.lock(); fifo.emplace(data); outlock.unlock(); - if(sender != this) + if(sender && (sender != this)) lock.lock(); ePoll.resetSocket(this); lock.unlock(); diff --git a/Socket.h b/Socket.h index 682ff5f..8d36251 100644 --- a/Socket.h +++ b/Socket.h @@ -86,7 +86,7 @@ namespace core { /// Write data to the socket. /// - int write(std::string data, Socket *sender); + int write(std::string data, Socket *sender = NULL); void write(char *buffer, int length); void output(std::stringstream &out); diff --git a/SubscriptionManager.cpp b/SubscriptionManager.cpp index 59ef3eb..93a4eb7 100644 --- a/SubscriptionManager.cpp +++ b/SubscriptionManager.cpp @@ -85,8 +85,6 @@ namespace core std::string invitee = request[2].str(); TCPSession *tempSession = session.server.getSessionByAlias(&invitee); std::stringstream temp; - // We need to utilize invite for different ways, group with people,and to generally invite into anything pertaining interaction//// - /// with another player// temp << "invite:" << request[1] << ":" << *(std::string *)session.alias; tempSession->write(temp.str()); return 1; diff --git a/TCPServer.cpp b/TCPServer.cpp index 27b8a3c..7fb5554 100644 --- a/TCPServer.cpp +++ b/TCPServer.cpp @@ -8,31 +8,7 @@ namespace core { TCPServer::TCPServer(EPoll &ePoll, IPAddress address, std::string delimiter, int depth, std::string text) -<<<<<<< HEAD - : TCPSocket(ePoll, text), commands(delimiter, depth) { - - commands.add(subscriptions, "publish"); - commands.add(subscriptions, "unpublish"); - commands.add(subscriptions, "subscribe"); - commands.add(subscriptions, "unsubscribe"); - commands.add(subscriptions, "catalog"); - commands.add(subscriptions, "event"); - - setDescriptor(socket(AF_INET, SOCK_STREAM, 0)); - int yes = 1; - setsockopt(getDescriptor(), SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)); - - if(bind(getDescriptor(), address.getPointer(), address.addressLength) < 0) - throw coreutils::Exception("Error on bind to socket: " + std::to_string(errno)); - - if(listen(getDescriptor(), 20) < 0) - throw coreutils::Exception("Error on listen to socket"); - - } -======= - : TCPSocket(ePoll, text), commands(delimiter, depth) - { ->>>>>>> subscription + : TCPSocket(ePoll, text), commands(delimiter, depth) { commands.add(subscriptions, "publish"); commands.add(subscriptions, "unpublish"); @@ -158,13 +134,9 @@ namespace core { coreutils::Log(coreutils::LOG_DEBUG_1) << alias; for (auto session : sessions) - if (compareAlias(session->alias, alias)) + if (session->compareAlias(alias)) return session; return NULL; } - bool TCPServer::compareAlias(void *alias, void *compare) - { - return alias == compare; - } } diff --git a/TCPServer.h b/TCPServer.h index 871b2fa..1feb96c 100644 --- a/TCPServer.h +++ b/TCPServer.h @@ -150,7 +150,6 @@ namespace core TCPSession *accept(); std::mutex lock; }; - /// This method is called when you compare an alias of the character } diff --git a/TCPSession.cpp b/TCPSession.cpp index c7904b6..5f4efb5 100644 --- a/TCPSession.cpp +++ b/TCPSession.cpp @@ -38,6 +38,10 @@ namespace core } } + bool TCPSession::compareAlias(void *alias) { + return this->alias = alias; + } + void TCPSession::onRegistered() { onConnected(); diff --git a/TCPSession.h b/TCPSession.h index a62da9f..1a3c17a 100644 --- a/TCPSession.h +++ b/TCPSession.h @@ -67,10 +67,30 @@ namespace core std::stringstream out; + /// + /// uuid is generated automatically when the session object is instantiated. This + /// value can be used to uniquely identify a session and is the default value + /// pointed to by the alias pointer. + /// + char uuid[37]; + /// + /// alias is a void pointer that can be set to point to any object that identifies + /// this session uniquely. Using this approach, inheriting objects can determine + /// how it knows the contacts that this server manages. + /// + void *alias; + /// + /// + /// + + virtual bool compareAlias(void *alias); + + virtual void outputAlias(std::stringstream &out); + protected: /// /// diff --git a/html/Socket_8h_source.html b/html/Socket_8h_source.html index f82c953..84d33e5 100644 --- a/html/Socket_8h_source.html +++ b/html/Socket_8h_source.html @@ -99,8 +99,8 @@ $(function() {
83  bool eventReceived(struct epoll_event event, long long eventId);
84 
88 
-
89  int write(std::string data, Socket *sender);
-
90  void write(char *buffer, int length);
+
89  int write(std::string data, Socket *sender = NULL);
+
90  void write(char *buffer, int length);
91 
92  void output(std::stringstream &out);
93 
@@ -178,33 +178,18 @@ $(function() {
198 
core::EPoll
Definition: EPoll.h:31
core::Socket
Definition: Socket.h:34
-<<<<<<< HEAD -
core::Socket::getDescriptor
int getDescriptor()
Get the descriptor for the socket.
Definition: Socket.cpp:43
-
core::Socket::eventReceived
bool eventReceived(struct epoll_event event, long long eventId)
Parse epoll event and call specified callbacks.
Definition: Socket.cpp:64
-
core::Socket::onRegistered
virtual void onRegistered()
Called after the socket has been registered with epoll processing.
Definition: Socket.cpp:58
-
core::Socket::receiveData
virtual void receiveData(coreutils::ZString &buffer)
Definition: Socket.cpp:94
-
core::Socket::Socket
Socket(EPoll &ePoll, std::string text="")
Definition: Socket.cpp:11
-
core::Socket::write
int write(std::string data, Socket *sender)
Definition: Socket.cpp:137
-
core::Socket::onRegister
virtual void onRegister()
Called before the socket has registered with the epoll processing.
Definition: Socket.cpp:56
-
core::Socket::~Socket
virtual ~Socket()
Definition: Socket.cpp:16
-
core::Socket::setDescriptor
void setDescriptor(int descriptor)
Set the descriptor for the socket.
Definition: Socket.cpp:28
-
core::Socket::onDataReceived
virtual void onDataReceived(std::string data)
Called when data is received from the socket.
Definition: Socket.cpp:86
-
core::Socket::onUnregistered
virtual void onUnregistered()
Called when the socket has finished unregistering for the epoll processing.
Definition: Socket.cpp:62
-
core::Socket::shutdown
void shutdown(std::string text="unknown")
Definition: Socket.cpp:156
-=======
core::Socket::getDescriptor
int getDescriptor()
Get the descriptor for the socket.
Definition: Socket.cpp:46
-
core::Socket::write
int write(std::string data)
Definition: Socket.cpp:146
core::Socket::eventReceived
bool eventReceived(struct epoll_event event, long long eventId)
Parse epoll event and call specified callbacks.
Definition: Socket.cpp:70
core::Socket::onRegistered
virtual void onRegistered()
Called after the socket has been registered with epoll processing.
Definition: Socket.cpp:64
-
core::Socket::receiveData
virtual void receiveData(coreutils::ZString &buffer)
Definition: Socket.cpp:101
+
core::Socket::receiveData
virtual void receiveData(coreutils::ZString &buffer)
Definition: Socket.cpp:102
core::Socket::Socket
Socket(EPoll &ePoll, std::string text="")
Definition: Socket.cpp:12
+
core::Socket::write
int write(std::string data, Socket *sender=NULL)
Definition: Socket.cpp:147
core::Socket::onRegister
virtual void onRegister()
Called before the socket has registered with the epoll processing.
Definition: Socket.cpp:62
core::Socket::~Socket
virtual ~Socket()
Definition: Socket.cpp:18
core::Socket::setDescriptor
void setDescriptor(int descriptor)
Set the descriptor for the socket.
Definition: Socket.cpp:30
-
core::Socket::onDataReceived
virtual void onDataReceived(std::string data)
Called when data is received from the socket.
Definition: Socket.cpp:91
+
core::Socket::onDataReceived
virtual void onDataReceived(std::string data)
Called when data is received from the socket.
Definition: Socket.cpp:92
core::Socket::onUnregistered
virtual void onUnregistered()
Called when the socket has finished unregistering for the epoll processing.
Definition: Socket.cpp:68
-
core::Socket::shutdown
void shutdown(std::string text="unknown")
Definition: Socket.cpp:167
->>>>>>> subscription +
core::Socket::shutdown
void shutdown(std::string text="unknown")
Definition: Socket.cpp:168