Back to index

glibc  2.9
Functions | Variables
hurdsock.c File Reference
#include <hurd.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <string.h>
#include <hurd/paths.h>
#include <stdio.h>
#include "stdio-common/_itoa.h"
#include <cthreads.h>
#include "hurdmalloc.h"

Go to the source code of this file.

Functions

socket_t _hurd_socket_server (int domain, int dead)
static void init (void)
 text_set_element (_hurd_preinit_hook, init)

Variables

static struct mutex
static file_t * servers
static int max_domain = -1

Function Documentation

socket_t _hurd_socket_server ( int  domain,
int  dead 
)

Definition at line 46 of file hurdsock.c.

{
  socket_t server;

  HURD_CRITICAL_BEGIN;
  __mutex_lock (&lock);

  if (domain > max_domain)
    {
      error_t save = errno;
      file_t *new = realloc (servers, (domain + 1) * sizeof (file_t));
      if (new != NULL)
       {
         do
           new[++max_domain] = MACH_PORT_NULL;
         while (max_domain < domain);
         servers = new;
       }
      else
       /* No space to cache the port; we will just fetch it anew below.  */
       errno = save;
    }

  if (dead && domain <= max_domain)
    {
      /* The user says the port we returned earlier (now in SERVERS[DOMAIN])
        was dead.  Clear the cache and fetch a new one below.  */
      __mach_port_deallocate (__mach_task_self (), servers[domain]);
      servers[domain] = MACH_PORT_NULL;
    }

  if (domain > max_domain || servers[domain] == MACH_PORT_NULL)
    {
      char name[sizeof (_SERVERS_SOCKET) + 100];
      char *np = &name[sizeof (name)];
      *--np = '\0';
      np = _itoa (domain, np, 10, 0);
      *--np = '/';
      np -= sizeof (_SERVERS_SOCKET) - 1;
      memcpy (np, _SERVERS_SOCKET, sizeof (_SERVERS_SOCKET) - 1);
      server = __file_name_lookup (np, 0, 0);
      if (domain <= max_domain)
       servers[domain] = server;
    }
  else
    server = servers[domain];

  if (server == MACH_PORT_NULL && errno == ENOENT)
    /* If the server node is absent, we don't support that protocol.  */
    errno = EAFNOSUPPORT;

  __mutex_unlock (&lock);
  HURD_CRITICAL_END;

  return server;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void init ( void  ) [static]

Definition at line 104 of file hurdsock.c.

{
  int i;

  __mutex_init (&lock);

  for (i = 0; i < max_domain; ++i)
    servers[i] = MACH_PORT_NULL;

  (void) &init;                    /* Avoid "defined but not used" warning.  */
}

Here is the call graph for this function:

text_set_element ( _hurd_preinit_hook  ,
init   
)

Variable Documentation

int max_domain = -1 [static]

Definition at line 33 of file hurdsock.c.

struct mutex [static]

Definition at line 30 of file hurdsock.c.

file_t* servers [static]

Definition at line 32 of file hurdsock.c.