Sometimes when you're hunting bugs on a production webserver (with multiple workers) you want to tcpdump and see what's going on.
This patch adds the memcached_server_srcport method to the library which returns the local sourceport of the connection (if there's a connection).
We use it a lot.
LIBMEMCACHED_API
in_port_t memcached_server_port(const memcached_instance_st * self);
+LIBMEMCACHED_API
+in_port_t memcached_server_srcport(const memcached_instance_st * self);
+
LIBMEMCACHED_API
void memcached_instance_next_retry(const memcached_instance_st * self, const time_t absolute_time);
return self->port();
}
+in_port_t memcached_server_srcport(const memcached_instance_st * self)
+{
+ WATCHPOINT_ASSERT(self);
+ if (self == NULL || self->fd == INVALID_SOCKET || (self->type != MEMCACHED_CONNECTION_TCP && self->type != MEMCACHED_CONNECTION_UDP))
+ {
+ return 0;
+ }
+
+ struct sockaddr_in sin;
+ socklen_t addrlen= sizeof(sin);
+ if (getsockname(self->fd, (struct sockaddr*)&sin, &addrlen) != -1)
+ {
+ return ntohs(sin.sin_port);
+ }
+
+ return -1;
+}
+
uint32_t memcached_server_response_count(const memcached_instance_st * self)
{
WATCHPOINT_ASSERT(self);