summaryrefslogtreecommitdiff
path: root/src/common/socket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/socket.cpp')
-rw-r--r--src/common/socket.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/common/socket.cpp b/src/common/socket.cpp
index 7eb4b46..7cd02e4 100644
--- a/src/common/socket.cpp
+++ b/src/common/socket.cpp
@@ -8,11 +8,9 @@
#define PORT 6969
-class Socket {
+struct Socket {
int descriptor;
- public:
-
Socket() {
descriptor = socket(AF_INET, SOCK_STREAM, 0);
}
@@ -60,14 +58,25 @@ class Socket {
::connect(descriptor, (sockaddr *) &addr, sizeof(sockaddr_in));
}
- size_t send(void *msg, size_t length) {
+ size_t send(const void *msg, size_t length) {
return write(descriptor, msg, length);
}
+ size_t send(Message &msg) {
+ size_t result = write(descriptor, msg.data, msg.offset);
+ msg.offset = 0;
+ return result;
+ }
+
size_t recv(void *msg, size_t length) {
return read(descriptor, msg, length);
}
+ size_t recv(Message &msg) {
+ msg.offset = 0;
+ return read(descriptor, msg.data, MESSAGE_SIZE);
+ }
+
~Socket() {
close(descriptor);
}