Exemple #1
0
/* 
 * Find a writer context or create a new one 
 * Note that the writer context will last until a io_close.
 */
static struct writer_context_s *
find_writer (int fd, int start_it)
{
    int i;

    for (i=0; i < writer_table_size ; i++ ) {
        if ( writer_table[i].used && writer_table[i].fd == fd )
            return writer_table[i].context;
    }
    if (!start_it)
        return NULL;

    LOCK (writer_table_lock);
    for (i=0; i < writer_table_size; i++ ) {
        if (!writer_table[i].used) {
            writer_table[i].fd = fd;
            writer_table[i].context = create_writer (fd_to_handle (fd));
            writer_table[i].used = 1;
            UNLOCK (writer_table_lock);
            return writer_table[i].context;
        }
    }
    UNLOCK (writer_table_lock);
    return NULL;
}
Exemple #2
0
/* Find a writer context or create a new one.  Note that the writer
   context will last until a _gpgme_io_close.  */
static struct writer_context_s *
find_writer (int fd, int start_it)
{
  struct writer_context_s *wt = NULL;
  int i;

  LOCK (writer_table_lock);
  for (i = 0; i < writer_table_size; i++)
    if (writer_table[i].used && writer_table[i].fd == fd)
      wt = writer_table[i].context;

  if (wt || !start_it)
    {
      UNLOCK (writer_table_lock);
      return wt;
    }

  for (i = 0; i < writer_table_size; i++)
    if (!writer_table[i].used)
      break;

  if (i != writer_table_size)
    {
      wt = create_writer (fd_to_handle (fd));
      if (wt)
	{
	  writer_table[i].fd = fd;
	  writer_table[i].context = wt; 
	  writer_table[i].used = 1;
	}
    }

  UNLOCK (writer_table_lock);
  return wt;
}
Exemple #3
0
HRESULT WINAPI CreateXmlWriterOutputWithEncodingCodePage(IUnknown *stream,
                                                         IMalloc *imalloc,
                                                         UINT codepage,
                                                         IXmlWriterOutput **output)
{
    xml_encoding xml_enc;

    TRACE("%p %p %u %p\n", stream, imalloc, codepage, output);

    if (!stream || !output) return E_INVALIDARG;

    xml_enc = get_encoding_from_codepage(codepage);
    return create_writer(stream, imalloc, xml_enc, output);
}
Exemple #4
0
HRESULT WINAPI CreateXmlWriterOutputWithEncodingName(IUnknown *stream,
                                                     IMalloc *imalloc,
                                                     LPCWSTR encoding,
                                                     IXmlWriterOutput **output)
{
    static const WCHAR utf8W[] = {'U','T','F','-','8',0};
    xml_encoding xml_enc;

    TRACE("%p %p %s %p\n", stream, imalloc, debugstr_w(encoding), output);

    if (!stream || !output) return E_INVALIDARG;

    xml_enc = parse_encoding_name(encoding ? encoding : utf8W, -1);
    return create_writer(stream, imalloc, xml_enc, output);
}
Exemple #5
0
// Initialize everything
static void init() {
    int error;

    // Open files
    error = create_reader();
    if (error != 0) {
        fprintf(stderr, "%s: %s\n", get_input(), strerror(errno));
        exit(1);
    }

    error = create_writer();
    if (error != 0) {
        fprintf(stderr, "%s: %s\n", get_output(), strerror(errno));
        exit(2);
    }

    // Basic Huffman tree
    init_variables();
}
Exemple #6
0
fievel_prer_t *fievel_new_prer_json(json_object *prer_conf, const char *server) {

    fievel_writer_t *writer = create_writer(prer_conf);
    if (writer == NULL) {
        LOG(LOG_LVL_CRIT, "Error parsing configuration file: "
                "OutputMethod isn't well defined!"
                "Maybe a wrong parameter?");
        return NULL;
    }

    fievel_prer_t *prer = malloc(fievel_prer_size());
    if (fievel_prer_construct(prer, writer, server, prer_conf) != NULL) {
        return prer;
    } else {
        free(prer);
        return NULL;
    }

}
Exemple #7
0
int main() {
    int sockfd, reuse = 1;
    struct sockaddr_in addr;

    create_reader();
    create_writer();

    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    if(sockfd == -1) {
        perror("socket()");
        exit(EXIT_FAILURE);
    }

    setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse));

    memset(&addr, 0, sizeof(struct sockaddr_in));

    addr.sin_family = AF_INET;
    addr.sin_port = htons(LISTEN_PORT);

    if(bind(sockfd, (struct sockaddr *) &addr, sizeof(struct sockaddr_in)) == -1) {
        perror("bind()");
        exit(EXIT_FAILURE);
    }

    if(listen(sockfd, LISTEN_BACKLOG) == -1) {
        perror("listen()");
        exit(EXIT_FAILURE);
    }

    fprintf(stderr, "listening on port %d\n", LISTEN_PORT);

    serve(sockfd);

    close(sockfd);

    exit(EXIT_SUCCESS);
}
Exemple #8
0
BufferAllocator::WriterPtr BufferAllocator::create_writer(size_t size, size_t prepend, size_t append) {
  auto ptr = create_writer(size + prepend + append);
  ptr->begin_ += prepend;
  ptr->end_ += prepend + size;
  return ptr;
}