static void*
handle_chargen(void *arg)
{
    int fd;
    int n, length;
    char buffer[BUFFER_SIZE];

    fd = *((int *) arg);
    free(arg);
    
    pthread_detach(pthread_self());
    
    length = 1400; /*+ (random() % 512);*/
    memset(buffer, 'A', length);
    buffer[length-1] = '\n';

    while ((n=ext_send(fd, buffer, length, 0)) >  0){
        if (vverbose) {
            printf("%-6d: sending %u bytes.\n", fd, n);
            fflush(stdout);
        }
        if (n != ext_send(fd, buffer, n, 0)) {
            printf("%-6d: Writing %u bytes failed.\n", fd, n);
        }
        length = 1400; /*+ (random() % 512)*/
        memset(buffer, 'A', length);
        buffer[length-1] = '\n';
    }
    ext_close(fd);
    if (verbose) {
        printf("%-6d: Connection closed.\n", fd);
        fflush(stdout);
    }
    return(NULL);
}
static void*
handle_daytime(void *arg)
{
    int fd;
    int timeAsStringLen;
    char *timeAsString;
    time_t now;

    fd = *((int *) arg);
    free(arg);
    
    pthread_detach(pthread_self());
    
    time(&now);
    timeAsString = ctime(&now);
    timeAsStringLen = strlen(timeAsString);
    
    if (timeAsStringLen != ext_send(fd, timeAsString, timeAsStringLen, 0)) {
            printf("%-6d: Writing the daytime failed.\n", fd);
    }
    if (vverbose) {
        printf("%-6d: Daytime sent back: %s", fd, timeAsString);
        fflush(stdout);
    }

    ext_close(fd);
    if (verbose) {
        printf("%-6d: Connection closed.\n", fd);
        fflush(stdout);
    }
    return(NULL);
}
static void*
handle_echo(void *arg)
{
    int fd;
    int n;
    char buffer[BUFFER_SIZE];

    fd = *((int *) arg);
    free(arg);
    
    pthread_detach(pthread_self());

    while ((n=ext_read(fd, buffer, sizeof(buffer))) >  0){
        if (vverbose) {
            printf("%-6d: Echoing %u bytes.\n", fd, n);
            fflush(stdout);
        }
        if (n != ext_send(fd, buffer, n, 0)) {
            printf("%-6d: Writing %u bytes failed.\n", fd, n);
        }
    }
    ext_close(fd);
    if (verbose) {
        printf("%-6d: Connection closed.\n", fd);
        fflush(stdout);
    }
    return(NULL);
}
Ejemplo n.º 4
0
	bool operator()()
	{
		if (conn) {
			obj_dosync();
			ext_send();
			ext_poll();
			if (!conn->good()) {
				conn = 0;
			}
		}
		if (die.try_wait()) {
			in_queue.clear();
			out_queue.clear();
			dead.signal();
			return false;
		} else {
			return true;
		}
	}