Update uS, add AsyncSocket::getRemoteAddress()

This commit is contained in:
Alex Hultman
2019-03-03 07:40:44 +01:00
parent 35e6bad33b
commit 495ccfc076
5 changed files with 13 additions and 2 deletions
+8
View File
@@ -87,6 +87,14 @@ protected:
return getAsyncSocketData()->buffer.size();
}
/* Returns the remote IP address or empty string on failure */
std::string_view getRemoteAddress() {
static thread_local char buf[16];
int ipLength = 16;
us_new_socket_remote_address(SSL, (us_new_socket_t *) this, buf, &ipLength);
return std::string_view(buf, ipLength);
}
/* Write in three levels of prioritization: cork-buffer, syscall, socket-buffer. Always drain if possible.
* Returns pair of bytes written (anywhere) and wheter or not this call resulted in the polling for
* writable (or we are in a state that implies polling for writable). */
+1 -1
View File
@@ -59,7 +59,7 @@ private:
/* Init the HttpContext by registering libusockets event handlers */
HttpContext<SSL> *init() {
/* Handle socket connections */
us_new_socket_context_on_open(SSL, getSocketContext(), [](auto *s, int is_client) {
us_new_socket_context_on_open(SSL, getSocketContext(), [](auto *s, int is_client, char *ip, int ip_length) {
/* Any connected socket should timeout until it has a request */
us_new_socket_timeout(SSL, s, HTTP_IDLE_TIMEOUT_S);
+2
View File
@@ -167,6 +167,8 @@ public:
/* Immediately terminate this Http response */
using Super::close;
using Super::getRemoteAddress;
/* Note: Headers are not checked in regards to timeout.
* We only check when you actively push data or end the request */
+1
View File
@@ -48,6 +48,7 @@ public:
/* See AsyncSocket */
using Super::getBufferedAmount;
using Super::getRemoteAddress;
/* Simple, immediate close of the socket. Emits close event */
using Super::close;