You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Tyler MacDonald <ty...@yi.org> on 2007/04/12 22:27:51 UTC

listener from a conn_rec?

Given a connection record, how do I determine what listener originally
accepted the connection? I've dug around the API documentation a bit and
can't find a clear path back to my listener or a protocol from a connection.
A connection should really know what protocol it's supposed to speak,
shouldn't it?

Here's what I came up with... of course, it falls apart as soon as you have
more than one protocol on the same port (maybe with different bind addresses
or whatever)...

static const char* what_protocol_am_i(conn_rec* c) {
  apr_port_t port = c->local_addr->port;
  ap_listen_rec* cur;
  char* rv;
  char* p;
  int i;
  for(cur = ap_listeners; cur != NULL; cur = cur->next) {
    if(cur->bind_addr->port == port) {
      rv = apr_pstrdup(c->pool, cur->protocol);
      for(p=rv;*p;p++)
        *p = tolower(*p);
      return rv;
    }
  }
  return NULL;
}

It seems like this is a bit too much work. Is there an easier way? I was
expecting something like "conn_rec->protocol" or "conn_rec->listener", but
no dice...

	Thanks,
		Tyler