From b63b4785cf85058cbea676ea725daee8c18ef40c Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Sat, 11 Feb 2023 17:24:25 -0800 Subject: [PATCH] Synced up to Matts code. --- .gitignore | 4 +- Socket.cpp | 2 +- Socket.h | 2 +- SubscriptionManager.cpp | 2 - TCPServer.cpp | 32 +------ TCPServer.h | 1 - TCPSession.cpp | 4 + TCPSession.h | 20 +++++ html/Socket_8h_source.html | 27 ++---- html/TCPServer_8h_source.html | 20 ++--- html/TCPSession_8h_source.html | 89 ++++++++++--------- html/classcore_1_1ConsoleServer-members.html | 2 +- html/classcore_1_1ConsoleServer.html | 8 +- html/classcore_1_1ConsoleSession-members.html | 80 ++++------------- html/classcore_1_1ConsoleSession.html | 13 +-- html/classcore_1_1Socket-members.html | 2 +- html/classcore_1_1Socket.html | 10 +-- html/classcore_1_1SubscriptionManager.html | 1 - html/classcore_1_1TCPServer-members.html | 2 +- html/classcore_1_1TCPServer.html | 8 +- html/classcore_1_1TCPSession-members.html | 82 ++++++++--------- html/classcore_1_1TCPSession.html | 43 +++++++-- html/classcore_1_1TCPSession2-members.html | 2 +- html/classcore_1_1TCPSession2.html | 4 +- html/classcore_1_1TCPSocket-members.html | 2 +- html/classcore_1_1TCPSocket.html | 4 +- html/classcore_1_1TLSServer-members.html | 2 +- html/classcore_1_1TLSServer.html | 8 +- html/classcore_1_1TLSSession-members.html | 56 ++---------- html/classcore_1_1TLSSession.html | 13 +-- .../classcore_1_1TerminalSession-members.html | 71 +++------------ html/classcore_1_1TerminalSession.html | 13 +-- .../classcore_1_1UDPServerSocket-members.html | 2 +- html/classcore_1_1UDPServerSocket.html | 4 +- html/classcore_1_1UDPSocket-members.html | 2 +- html/classcore_1_1UDPSocket.html | 4 +- html/functions.html | 8 +- html/functions_func.html | 2 +- html/functions_vars.html | 6 ++ html/search/all_0.js | 3 +- html/search/all_1.js | 2 +- html/search/all_2.js | 16 ++-- html/search/all_3.js | 4 +- html/search/all_4.js | 16 ++-- html/search/all_5.js | 8 +- html/search/all_6.js | 2 +- html/search/all_7.js | 22 ++--- html/search/all_8.js | 6 +- html/search/all_9.js | 6 +- html/search/all_a.js | 32 +++---- html/search/all_b.js | 22 ++--- html/search/all_c.js | 7 +- html/search/all_d.js | 9 +- html/search/all_e.js | 8 +- html/search/classes_0.js | 8 +- html/search/classes_1.js | 2 +- html/search/classes_2.js | 6 +- html/search/classes_3.js | 2 +- html/search/classes_4.js | 10 +-- html/search/classes_5.js | 20 ++--- html/search/classes_6.js | 4 +- html/search/functions_0.js | 2 +- html/search/functions_1.js | 6 +- html/search/functions_2.js | 4 +- html/search/functions_3.js | 16 ++-- html/search/functions_4.js | 2 +- html/search/functions_5.js | 18 ++-- html/search/functions_6.js | 6 +- html/search/functions_7.js | 6 +- html/search/functions_8.js | 20 ++--- html/search/functions_9.js | 6 +- html/search/functions_a.js | 2 +- html/search/functions_b.js | 6 +- html/search/functions_c.js | 8 +- html/search/searchdata.js | 2 +- html/search/variables_0.js | 2 +- html/search/variables_1.js | 2 +- html/search/variables_2.js | 2 +- html/search/variables_3.js | 2 +- html/search/variables_4.js | 3 +- html/search/variables_5.js | 3 +- latex/classcore_1_1Socket.tex | 6 +- latex/classcore_1_1SubscriptionManager.tex | 2 +- latex/classcore_1_1TCPServer.tex | 2 +- latex/classcore_1_1TCPSession.tex | 25 ++++-- 85 files changed, 458 insertions(+), 567 deletions(-) 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 
Definition: EPoll.h:31
Definition: Socket.h:34
-<<<<<<< HEAD -
int getDescriptor()
Get the descriptor for the socket.
Definition: Socket.cpp:43
-
bool eventReceived(struct epoll_event event, long long eventId)
Parse epoll event and call specified callbacks.
Definition: Socket.cpp:64
-
virtual void onRegistered()
Called after the socket has been registered with epoll processing.
Definition: Socket.cpp:58
-
virtual void receiveData(coreutils::ZString &buffer)
Definition: Socket.cpp:94
-
Socket(EPoll &ePoll, std::string text="")
Definition: Socket.cpp:11
-
int write(std::string data, Socket *sender)
Definition: Socket.cpp:137
-
virtual void onRegister()
Called before the socket has registered with the epoll processing.
Definition: Socket.cpp:56
-
virtual ~Socket()
Definition: Socket.cpp:16
-
void setDescriptor(int descriptor)
Set the descriptor for the socket.
Definition: Socket.cpp:28
-
virtual void onDataReceived(std::string data)
Called when data is received from the socket.
Definition: Socket.cpp:86
-
virtual void onUnregistered()
Called when the socket has finished unregistering for the epoll processing.
Definition: Socket.cpp:62
-
void shutdown(std::string text="unknown")
Definition: Socket.cpp:156
-=======
int getDescriptor()
Get the descriptor for the socket.
Definition: Socket.cpp:46
-
int write(std::string data)
Definition: Socket.cpp:146
bool eventReceived(struct epoll_event event, long long eventId)
Parse epoll event and call specified callbacks.
Definition: Socket.cpp:70
virtual void onRegistered()
Called after the socket has been registered with epoll processing.
Definition: Socket.cpp:64
-
virtual void receiveData(coreutils::ZString &buffer)
Definition: Socket.cpp:101
+
virtual void receiveData(coreutils::ZString &buffer)
Definition: Socket.cpp:102
Socket(EPoll &ePoll, std::string text="")
Definition: Socket.cpp:12
+
int write(std::string data, Socket *sender=NULL)
Definition: Socket.cpp:147
virtual void onRegister()
Called before the socket has registered with the epoll processing.
Definition: Socket.cpp:62
virtual ~Socket()
Definition: Socket.cpp:18
void setDescriptor(int descriptor)
Set the descriptor for the socket.
Definition: Socket.cpp:30
-
virtual void onDataReceived(std::string data)
Called when data is received from the socket.
Definition: Socket.cpp:91
+
virtual void onDataReceived(std::string data)
Called when data is received from the socket.
Definition: Socket.cpp:92
virtual void onUnregistered()
Called when the socket has finished unregistering for the epoll processing.
Definition: Socket.cpp:68
-
void shutdown(std::string text="unknown")
Definition: Socket.cpp:167
->>>>>>> subscription +
void shutdown(std::string text="unknown")
Definition: Socket.cpp:168