trim headers and unused code in IXUdpSocket
This commit is contained in:
		| @@ -36,6 +36,7 @@ set(IXBOTS_INCLUDE_DIRS | |||||||
|     . |     . | ||||||
|     .. |     .. | ||||||
|     ../ixcore |     ../ixcore | ||||||
|  |     ../ixwebsocket | ||||||
|     ../ixcobra |     ../ixcobra | ||||||
|     ../ixsentry |     ../ixsentry | ||||||
|     ${JSONCPP_INCLUDE_DIRS} |     ${JSONCPP_INCLUDE_DIRS} | ||||||
|   | |||||||
| @@ -39,12 +39,15 @@ | |||||||
|  |  | ||||||
| #include "IXStatsdClient.h" | #include "IXStatsdClient.h" | ||||||
|  |  | ||||||
|  | #include <ixwebsocket/IXNetSystem.h> | ||||||
| #include <stdlib.h> | #include <stdlib.h> | ||||||
| #include <string.h> | #include <string.h> | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
|  |  | ||||||
| namespace ix | namespace ix | ||||||
| { | { | ||||||
|  |     const uint64_t StatsdClient::_maxQueueSize = 32768; | ||||||
|  |  | ||||||
|     StatsdClient::StatsdClient(const std::string& host, |     StatsdClient::StatsdClient(const std::string& host, | ||||||
|                                int port, |                                int port, | ||||||
|                                const std::string& prefix) |                                const std::string& prefix) | ||||||
| @@ -56,18 +59,18 @@ namespace ix | |||||||
|         _thread = std::thread([this] { |         _thread = std::thread([this] { | ||||||
|             while (!_stop) |             while (!_stop) | ||||||
|             { |             { | ||||||
|                 std::deque<std::string> staged_message_queue; |                 std::deque<std::string> stagedQueue; | ||||||
|  |  | ||||||
|                 { |                 { | ||||||
|                     std::lock_guard<std::mutex> lock(_mutex); |                     std::lock_guard<std::mutex> lock(_mutex); | ||||||
|                     batching_message_queue_.swap(staged_message_queue); |                     _queue.swap(stagedQueue); | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 while (!staged_message_queue.empty()) |                 while (!stagedQueue.empty()) | ||||||
|                 { |                 { | ||||||
|                     auto message = staged_message_queue.front(); |                     auto message = stagedQueue.front(); | ||||||
|                     _socket.sendto(message); |                     _socket.sendto(message); | ||||||
|                     staged_message_queue.pop_front(); |                     stagedQueue.pop_front(); | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 std::this_thread::sleep_for(std::chrono::seconds(1)); |                 std::this_thread::sleep_for(std::chrono::seconds(1)); | ||||||
| @@ -139,14 +142,14 @@ namespace ix | |||||||
|     { |     { | ||||||
|         std::lock_guard<std::mutex> lock(_mutex); |         std::lock_guard<std::mutex> lock(_mutex); | ||||||
|  |  | ||||||
|         if (batching_message_queue_.empty() || |         if (_queue.empty() || | ||||||
|             batching_message_queue_.back().length() > max_batching_size) |             _queue.back().length() > _maxQueueSize) | ||||||
|         { |         { | ||||||
|             batching_message_queue_.push_back(message); |             _queue.push_back(message); | ||||||
|         } |         } | ||||||
|         else |         else | ||||||
|         { |         { | ||||||
|             (*batching_message_queue_.rbegin()).append("\n").append(message); |             (*_queue.rbegin()).append("\n").append(message); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return 0; |         return 0; | ||||||
|   | |||||||
| @@ -6,7 +6,6 @@ | |||||||
|  |  | ||||||
| #pragma once | #pragma once | ||||||
|  |  | ||||||
| #include <ixwebsocket/IXNetSystem.h> |  | ||||||
| #include <ixwebsocket/IXUdpSocket.h> | #include <ixwebsocket/IXUdpSocket.h> | ||||||
|  |  | ||||||
| #include <string> | #include <string> | ||||||
| @@ -15,9 +14,10 @@ | |||||||
| #include <mutex> | #include <mutex> | ||||||
| #include <atomic> | #include <atomic> | ||||||
|  |  | ||||||
| namespace ix { | namespace ix | ||||||
|  | { | ||||||
|     class StatsdClient { |     class StatsdClient | ||||||
|  |     { | ||||||
|     public: |     public: | ||||||
|         StatsdClient(const std::string& host="127.0.0.1", |         StatsdClient(const std::string& host="127.0.0.1", | ||||||
|                      int port=8125, |                      int port=8125, | ||||||
| @@ -55,8 +55,8 @@ namespace ix { | |||||||
|         std::thread _thread; |         std::thread _thread; | ||||||
|         std::mutex _mutex; // for the queue |         std::mutex _mutex; // for the queue | ||||||
|  |  | ||||||
|         std::deque<std::string> batching_message_queue_; |         std::deque<std::string> _queue; | ||||||
|         const uint64_t max_batching_size = 32768; |         static const uint64_t _maxQueueSize; | ||||||
|     }; |     }; | ||||||
|  |  | ||||||
| } // end namespace ix | } // end namespace ix | ||||||
|   | |||||||
| @@ -7,28 +7,13 @@ | |||||||
| #include "IXUdpSocket.h" | #include "IXUdpSocket.h" | ||||||
|  |  | ||||||
| #include "IXNetSystem.h" | #include "IXNetSystem.h" | ||||||
| #include "IXSelectInterrupt.h" |  | ||||||
| #include "IXSelectInterruptFactory.h" |  | ||||||
| #include "IXSocketConnect.h" |  | ||||||
| #include <algorithm> |  | ||||||
| #include <assert.h> |  | ||||||
| #include <fcntl.h> |  | ||||||
| #include <sstream> | #include <sstream> | ||||||
| #include <stdint.h> | #include <strings.h> | ||||||
| #include <stdio.h> |  | ||||||
| #include <stdlib.h> |  | ||||||
| #include <string.h> |  | ||||||
| #include <sys/types.h> |  | ||||||
|  |  | ||||||
| #ifdef min |  | ||||||
| #undef min |  | ||||||
| #endif |  | ||||||
|  |  | ||||||
| namespace ix | namespace ix | ||||||
| { | { | ||||||
|     UdpSocket::UdpSocket(int fd) |     UdpSocket::UdpSocket(int fd) | ||||||
|         : _sockfd(fd) |         : _sockfd(fd) | ||||||
|         , _selectInterrupt(createSelectInterrupt()) |  | ||||||
|     { |     { | ||||||
|         ; |         ; | ||||||
|     } |     } | ||||||
| @@ -40,8 +25,6 @@ namespace ix | |||||||
|  |  | ||||||
|     void UdpSocket::close() |     void UdpSocket::close() | ||||||
|     { |     { | ||||||
|         std::lock_guard<std::mutex> lock(_socketMutex); |  | ||||||
|  |  | ||||||
|         if (_sockfd == -1) return; |         if (_sockfd == -1) return; | ||||||
|  |  | ||||||
|         closeSocket(_sockfd); |         closeSocket(_sockfd); | ||||||
| @@ -61,18 +44,6 @@ namespace ix | |||||||
|         return err; |         return err; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     bool UdpSocket::isWaitNeeded() |  | ||||||
|     { |  | ||||||
|         int err = getErrno(); |  | ||||||
|  |  | ||||||
|         if (err == EWOULDBLOCK || err == EAGAIN || err == EINPROGRESS) |  | ||||||
|         { |  | ||||||
|             return true; |  | ||||||
|         } |  | ||||||
|  |  | ||||||
|         return false; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     void UdpSocket::closeSocket(int fd) |     void UdpSocket::closeSocket(int fd) | ||||||
|     { |     { | ||||||
| #ifdef _WIN32 | #ifdef _WIN32 | ||||||
|   | |||||||
| @@ -7,59 +7,34 @@ | |||||||
| #pragma once | #pragma once | ||||||
|  |  | ||||||
| #include <atomic> | #include <atomic> | ||||||
| #include <functional> |  | ||||||
| #include <memory> | #include <memory> | ||||||
| #include <mutex> |  | ||||||
| #include <string> | #include <string> | ||||||
|  |  | ||||||
| #ifdef _WIN32 | #ifdef _WIN32 | ||||||
| #include <BaseTsd.h> | #include <BaseTsd.h> | ||||||
| typedef SSIZE_T ssize_t; | typedef SSIZE_T ssize_t; | ||||||
|  |  | ||||||
| #undef EWOULDBLOCK |  | ||||||
| #undef EAGAIN |  | ||||||
| #undef EINPROGRESS |  | ||||||
| #undef EBADF |  | ||||||
| #undef EINVAL |  | ||||||
|  |  | ||||||
| // map to WSA error codes |  | ||||||
| #define EWOULDBLOCK WSAEWOULDBLOCK |  | ||||||
| #define EAGAIN WSATRY_AGAIN |  | ||||||
| #define EINPROGRESS WSAEINPROGRESS |  | ||||||
| #define EBADF WSAEBADF |  | ||||||
| #define EINVAL WSAEINVAL |  | ||||||
|  |  | ||||||
| #endif | #endif | ||||||
|  |  | ||||||
| #include "IXCancellationRequest.h" |  | ||||||
| #include "IXNetSystem.h" | #include "IXNetSystem.h" | ||||||
|  |  | ||||||
| namespace ix | namespace ix | ||||||
| { | { | ||||||
|     class SelectInterrupt; |  | ||||||
|  |  | ||||||
|     class UdpSocket |     class UdpSocket | ||||||
|     { |     { | ||||||
|     public: |     public: | ||||||
|         UdpSocket(int fd = -1); |         UdpSocket(int fd = -1); | ||||||
|         virtual ~UdpSocket(); |         ~UdpSocket(); | ||||||
|  |  | ||||||
|         // Virtual methods |         // Virtual methods | ||||||
|         bool init(const std::string& host, int port, std::string& errMsg); |         bool init(const std::string& host, int port, std::string& errMsg); | ||||||
|         ssize_t sendto(const std::string& buffer); |         ssize_t sendto(const std::string& buffer); | ||||||
|         virtual void close(); |         void close(); | ||||||
|  |  | ||||||
|         static int getErrno(); |         static int getErrno(); | ||||||
|         static bool isWaitNeeded(); |  | ||||||
|         static void closeSocket(int fd); |         static void closeSocket(int fd); | ||||||
|  |  | ||||||
|     protected: |  | ||||||
|         std::atomic<int> _sockfd; |  | ||||||
|         std::mutex _socketMutex; |  | ||||||
|  |  | ||||||
|         struct sockaddr_in _server; |  | ||||||
|  |  | ||||||
|     private: |     private: | ||||||
|         std::shared_ptr<SelectInterrupt> _selectInterrupt; |         std::atomic<int> _sockfd; | ||||||
|  |         struct sockaddr_in _server; | ||||||
|     }; |     }; | ||||||
| } // namespace ix | } // namespace ix | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user