예제 #1
0
void
sp_writer_free_block (ShmBlock * block)
{
    shm_alloc_space_block_dec (block->ablock);
    sp_shm_area_dec (block->pipe, block->area);
    spalloc_free (ShmBlock, block);
}
예제 #2
0
ShmPipe *
sp_client_open (const char *path)
{
    ShmPipe *self = spalloc_new (ShmPipe);
    struct sockaddr_un sun;

    memset (self, 0, sizeof (ShmPipe));

    self->main_socket = socket (PF_UNIX, SOCK_STREAM, 0);
    if (self->main_socket < 0) {
        sp_close (self);
        return NULL;
    }

    sun.sun_family = AF_UNIX;
    strncpy (sun.sun_path, path, sizeof (sun.sun_path) - 1);

    if (connect (self->main_socket, (struct sockaddr *) &sun,
                 sizeof (struct sockaddr_un)) < 0)
        goto error;

    return self;

error:
    spalloc_free (ShmPipe, self);
    return NULL;
}
예제 #3
0
static void
sp_dec (ShmPipe * self)
{
  self->use_count--;

  if (self->use_count > 0)
    return;

  while (self->shm_area)
    sp_shm_area_dec (self, self->shm_area);

  spalloc_free (ShmPipe, self);
}
예제 #4
0
void
sp_writer_close_client (ShmPipe * self, ShmClient * client,
    sp_buffer_free_callback callback, void *user_data)
{
  ShmBuffer *buffer = NULL, *prev_buf = NULL;
  ShmClient *item = NULL, *prev_item = NULL;

  shutdown (client->fd, SHUT_RDWR);
  close (client->fd);

again:
  for (buffer = self->buffers; buffer; buffer = buffer->next) {
    int i;
    void *tag = NULL;

    for (i = 0; i < buffer->num_clients; i++) {
      if (buffer->clients[i] == client->fd) {
        if (!sp_shmbuf_dec (self, buffer, prev_buf, client, &tag)) {
          if (callback)
            callback (tag, user_data);
          goto again;
        }
        break;
      }
    }
    prev_buf = buffer;
  }

  for (item = self->clients; item; item = item->next) {
    if (item == client)
      break;
    prev_item = item;
  }
  assert (item);

  if (prev_item)
    prev_item->next = client->next;
  else
    self->clients = client->next;

  self->num_clients--;

  spalloc_free (ShmClient, client);
}
예제 #5
0
void
sp_close (ShmPipe * self)
{
    if (self->main_socket >= 0)
        close (self->main_socket);

    if (self->socket_path) {
        unlink (self->socket_path);
        free (self->socket_path);
    }

    while (self->clients)
        sp_writer_close_client (self, self->clients);

    while (self->shm_area) {
        sp_shm_area_dec (self, self->shm_area);
    }

    spalloc_free (ShmPipe, self);
}
예제 #6
0
static void
sp_close_shm (ShmArea * area)
{
  assert (area->use_count == 0);

  if (area->allocspace)
    shm_alloc_space_free (area->allocspace);

  if (area->shm_area_buf != MAP_FAILED)
    munmap (area->shm_area_buf, area->shm_area_len);

  if (area->shm_fd >= 0)
    close (area->shm_fd);

  if (area->shm_area_name) {
    shm_unlink (area->shm_area_name);
    free (area->shm_area_name);
  }

  spalloc_free (ShmArea, area);
}
예제 #7
0
void
sp_writer_close_client (ShmPipe * self, ShmClient * client)
{
    ShmBuffer *buffer = NULL, *prev_buf = NULL;
    ShmClient *item = NULL, *prev_item = NULL;

    close (client->fd);

again:
    for (buffer = self->buffers; buffer; buffer = buffer->next) {
        int i;

        for (i = 0; i < buffer->num_clients; i++) {
            if (buffer->clients[i] == client->fd) {
                buffer->clients[i] = -1;
                if (!sp_shmbuf_dec (self, buffer, prev_buf))
                    goto again;
                break;
            }
            prev_buf = buffer;
        }
    }

    for (item = self->clients; item; item = item->next) {
        if (item == client)
            break;
        prev_item = item;
    }
    assert (item);

    if (prev_item)
        prev_item->next = client->next;
    else
        self->clients = client->next;

    self->num_clients--;

    spalloc_free (ShmClient, client);
}
예제 #8
0
static void
sp_close_shm (ShmPipe * self, ShmArea * area)
{
    assert (area->use_count == 0);

    if (area->allocspace)
        shm_alloc_space_free (area->allocspace);

    if (self != NULL) {
        ShmArea *item = NULL;
        ShmArea *prev_item = NULL;

        for (item = self->shm_area; item; item = item->next) {
            if (item == area) {
                if (prev_item)
                    prev_item->next = item->next;
                else
                    self->shm_area = item->next;
                break;
            }
            prev_item = item;
        }
        assert (item);
    }

    if (area->shm_area != MAP_FAILED)
        munmap (area->shm_area, area->shm_area_len);

    if (area->shm_fd >= 0)
        close (area->shm_fd);

    if (area->shm_area_name) {
        shm_unlink (area->shm_area_name);
        free (area->shm_area_name);
    }

    spalloc_free (ShmArea, area);
}