<commit_before>/*
 * The contents of this file are subject to the MonetDB Public
 * License Version 1.0 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of
 * the License at
 * http://monetdb.cwi.nl/Legal/MonetDBPL-1.0.html
 *
 * Software distributed under the License is distributed on an
 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * rights and limitations under the License.
 *
 * The Original Code is the Monet Database System.
 *
 * The Initial Developer of the Original Code is CWI.
 * Portions created by CWI are Copyright (C) 1997-2002 CWI.
 * All Rights Reserved.
 *
 * Contributor(s):
 * 		<NAME>  <<EMAIL>>
 * 		<NAME>  <<EMAIL>>
 * 		<NAME>  <<EMAIL>>
 * 		<NAME>  <<EMAIL>>
 */

#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <signal.h>
#include <errno.h>
#include <sys/time.h>
#include <unistd.h>
#include <stream.h>

#include <mem.h>
#include "comm.h"

/* returns a socket descriptor (>= 0) or an error code (< 0) */
int client(char *host, int port ){
    struct sockaddr_in server;
    struct hostent * host_info;
    int sock;

    if ((sock = socket (AF_INET, SOCK_STREAM, 0)) < 0) {
      fprintf (stderr, "client: could not open socket\n");
      return -2;
    }

    if (!(host_info = gethostbyname (host))) {
      fprintf (stderr, "client: unknown host %s\n", host);
      return -3;
    }

    server.sin_family = host_info -> h_addrtype;
    memcpy ((char *) &server.sin_addr,
            host_info -> h_addr,
            host_info -> h_length);
    server.sin_port = htons (port);

    if (connect (sock, (struct sockaddr *) &server, sizeof server) < 0) {
      fprintf (stderr, "client: could not connect to server\n");
      return -4;
    }

    return sock;
}

char *readblock( stream *s ){
	int len = 0;
	int size = BLOCK + 1;
	char *buf = NEW_ARRAY(char, size ), *start = buf;

	while ((len = s->read(s, start, 1, BLOCK)) == BLOCK){
		size += BLOCK;
		buf = RENEW_ARRAY(char, buf, size); 
		start = buf + size - BLOCK - 1;
		*start = '\0';
	}
	start += len;
	*start = '\0';
	return buf;
}

<commit_msg>wrap some includes in the proper #ifdef's (for windoz ...)<commit_after>/*
 * The contents of this file are subject to the MonetDB Public
 * License Version 1.0 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of
 * the License at
 * http://monetdb.cwi.nl/Legal/MonetDBPL-1.0.html
 *
 * Software distributed under the License is distributed on an
 * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * rights and limitations under the License.
 *
 * The Original Code is the Monet Database System.
 *
 * The Initial Developer of the Original Code is CWI.
 * Portions created by CWI are Copyright (C) 1997-2002 CWI.
 * All Rights Reserved.
 *
 * Contributor(s):
 * 		<NAME>  <<EMAIL>>
 * 		<NAME>  <<EMAIL>>
 * 		<NAME>  <<EMAIL>>
 * 		<NAME>  <<EMAIL>>
 */

#include <stdlib.h>
#include <sys/types.h>
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_NETDB_H
#include <netinet/in.h>
#include <netdb.h>
#endif
#include <stdio.h>
#include <signal.h>
#include <errno.h>
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
#else
# if HAVE_SYS_TIME_H
#  include <sys/time.h>
# else
#  include <time.h>
# endif
#endif
#include <unistd.h>
#include <stream.h>

#include <mem.h>
#include "comm.h"

/* returns a socket descriptor (>= 0) or an error code (< 0) */
int client(char *host, int port ){
    struct sockaddr_in server;
    struct hostent * host_info;
    int sock;

    if ((sock = socket (AF_INET, SOCK_STREAM, 0)) < 0) {
      fprintf (stderr, "client: could not open socket\n");
      return -2;
    }

    if (!(host_info = gethostbyname (host))) {
      fprintf (stderr, "client: unknown host %s\n", host);
      return -3;
    }

    server.sin_family = host_info -> h_addrtype;
    memcpy ((char *) &server.sin_addr,
            host_info -> h_addr,
            host_info -> h_length);
    server.sin_port = htons (port);

    if (connect (sock, (struct sockaddr *) &server, sizeof server) < 0) {
      fprintf (stderr, "client: could not connect to server\n");
      return -4;
    }

    return sock;
}

char *readblock( stream *s ){
	int len = 0;
	int size = BLOCK + 1;
	char *buf = NEW_ARRAY(char, size ), *start = buf;

	while ((len = s->read(s, start, 1, BLOCK)) == BLOCK){
		size += BLOCK;
		buf = RENEW_ARRAY(char, buf, size); 
		start = buf + size - BLOCK - 1;
		*start = '\0';
	}
	start += len;
	*start = '\0';
	return buf;
}


{'fraction_non_alphanumeric': 0.14052697616060225, 'fraction_numerical': 0.010874111250522794, 'mean_word_length': 3.067176870748299, 'pattern_counts': {'":': 0, '<': 60, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6848696', 'n_tokens_mistral': 1727, 'n_tokens_neox': 1646, 'n_words': 563}