<commit_before>/*
 * Copyright 2001 - 2009 <NAME>
 *
 * This file is part of Blister - a light weight, scalable, high performance
 * C++ server infrastructure.
 *
 * Blister is free software: you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or any later version.
 *
 * Blister is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Blister. If not, see <http://www.gnu.org/licenses/>.
 */

#include "stdapi.h"
#include <fcntl.h>
#include <signal.h>
#include <sys/stat.h>
#ifndef _WIN32
#include <sys/resource.h>
#endif
#include "Config.h"
#include "Dispatch.h"
#include "Log.h"
#include "Timing.h"

static const tchar *NAME = T("echo");

const int TIMEOUT = 10 * 1000;
const int MAXREAD = 16 * 1024;

class EchoTest: public Dispatcher {
public:
    EchoTest(): Dispatcher(cfg) {}
    virtual ~EchoTest() {}

    class EchoClientSocket: public DispatchClientSocket {
    public:
	EchoClientSocket(EchoTest &es, const Sockaddr &a, ulong t, ulong w):
	    DispatchClientSocket(es), addr(a), tmt(t), wait(w) {}
	virtual ~EchoClientSocket() {}

	virtual void start(uint tmt) { timeout(start, tmt); }

    protected:
	const Sockaddr &addr;
	usec_t begin;
	uint in, out, tmt, wait;

	virtual void onConnect(void);

	DSP_DECLARE(EchoClientSocket, input);
	DSP_DECLARE(EchoClientSocket, output);
	DSP_DECLARE(EchoClientSocket, repeat);
	DSP_DECLARE(EchoClientSocket, start);
    };

    class EchoServerSocket: public DispatchServerSocket {
    public:
	EchoServerSocket(Dispatcher &dspr, Socket &sock):
	    DispatchServerSocket(dspr, sock), buf(NULL) {}
	virtual ~EchoServerSocket() { delete [] buf; }

	void timeout(ulong timeout) { tmt = timeout; }
	static const tchar *section(void) { return NAME; }

	virtual void start(void) {
	    nagle(false);
	    readable(input, tmt);
	}

    private:
	char *buf;
	int in, out;
	ulong tmt;

	DSP_DECLARE(EchoServerSocket, input);
	DSP_DECLARE(EchoServerSocket, output);
    };

    class EchoListenSocket: public SimpleDispatchListenSocket<EchoTest,
	EchoServerSocket> {
    public:
	EchoListenSocket(EchoTest &dspr, ulong timeout):
	    SimpleDispatchListenSocket<EchoTest, EchoServerSocket>(dspr, SOCK_STREAM, false),
	    tmt(timeout) {}

	void start(EchoServerSocket &ess) { ess.timeout(tmt); ess.start(); }

    private:
	ulong tmt;
    };

    bool listen(const tchar *host, ulong timeout);
    void connect(const Sockaddr &a, ulong count, ulong delay, ulong timeout,
	ulong wait);

private:
    Config cfg;
};

static int loops = -1;
static char *data;
static ulong dsz;
static volatile bool qflag;
static TSNumber<uint> ops, errs;
static TSNumber<usec_t> usecs;

void EchoTest::EchoClientSocket::onConnect(void) {
    if (msg == Dispatcher::Timeout || msg == Dispatcher::Close) {
	errs++;
	dloge(T("client connect"), msg == Dispatcher::Timeout ? T("timeout") :
	    T("close"));
	erase();
    } else {
	nagle(false);
	begin = microticks();
	output();
    }
}

void EchoTest::EchoClientSocket::start() {
    close();
    out = 0;
    dlogd(T("connecting"));
    connect(addr, tmt);
}

void EchoTest::EchoClientSocket::output() {
    int len;

    if (!loops || qflag) {
	write(T(""), 1);
	erase();
	return;
    }
    if (loops != -1)
	loops--;<commit_msg>rename nodelay<commit_after>/*
 * Copyright 2001 - 2009 <NAME>
 *
 * This file is part of Blister - a light weight, scalable, high performance
 * C++ server infrastructure.
 *
 * Blister is free software: you can redistribute it and/or modify it under the
 * terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or any later version.
 *
 * Blister is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Blister. If not, see <http://www.gnu.org/licenses/>.
 */

#include "stdapi.h"
#include <fcntl.h>
#include <signal.h>
#include <sys/stat.h>
#ifndef _WIN32
#include <sys/resource.h>
#endif
#include "Config.h"
#include "Dispatch.h"
#include "Log.h"
#include "Timing.h"

static const tchar *NAME = T("echo");

const int TIMEOUT = 10 * 1000;
const int MAXREAD = 16 * 1024;

class EchoTest: public Dispatcher {
public:
    EchoTest(): Dispatcher(cfg) {}
    virtual ~EchoTest() {}

    class EchoClientSocket: public DispatchClientSocket {
    public:
	EchoClientSocket(EchoTest &es, const Sockaddr &a, ulong t, ulong w):
	    DispatchClientSocket(es), addr(a), tmt(t), wait(w) {}
	virtual ~EchoClientSocket() {}

	virtual void start(uint tmt) { timeout(start, tmt); }

    protected:
	const Sockaddr &addr;
	usec_t begin;
	uint in, out, tmt, wait;

	virtual void onConnect(void);

	DSP_DECLARE(EchoClientSocket, input);
	DSP_DECLARE(EchoClientSocket, output);
	DSP_DECLARE(EchoClientSocket, repeat);
	DSP_DECLARE(EchoClientSocket, start);
    };

    class EchoServerSocket: public DispatchServerSocket {
    public:
	EchoServerSocket(Dispatcher &dspr, Socket &sock):
	    DispatchServerSocket(dspr, sock), buf(NULL) {}
	virtual ~EchoServerSocket() { delete [] buf; }

	void timeout(ulong timeout) { tmt = timeout; }
	static const tchar *section(void) { return NAME; }

	virtual void start(void) {
	    nodelay(true);
	    readable(input, tmt);
	}

    private:
	char *buf;
	int in, out;
	ulong tmt;

	DSP_DECLARE(EchoServerSocket, input);
	DSP_DECLARE(EchoServerSocket, output);
    };

    class EchoListenSocket: public SimpleDispatchListenSocket<EchoTest,
	EchoServerSocket> {
    public:
	EchoListenSocket(EchoTest &dspr, ulong timeout):
	    SimpleDispatchListenSocket<EchoTest, EchoServerSocket>(dspr, SOCK_STREAM, false),
	    tmt(timeout) {}

	void start(EchoServerSocket &ess) { ess.timeout(tmt); ess.start(); }

    private:
	ulong tmt;
    };

    bool listen(const tchar *host, ulong timeout);
    void connect(const Sockaddr &a, ulong count, ulong delay, ulong timeout,
	ulong wait);

private:
    Config cfg;
};

static int loops = -1;
static char *data;
static ulong dsz;
static volatile bool qflag;
static TSNumber<uint> ops, errs;
static TSNumber<usec_t> usecs;

void EchoTest::EchoClientSocket::onConnect(void) {
    if (msg == Dispatcher::Timeout || msg == Dispatcher::Close) {
	errs++;
	dloge(T("client connect"), msg == Dispatcher::Timeout ? T("timeout") :
	    T("close"));
	erase();
    } else {
	nodelay(true);
	begin = microticks();
	output();
    }
}

void EchoTest::EchoClientSocket::start() {
    close();
    out = 0;
    dlogd(T("connecting"));
    connect(addr, tmt);
}

void EchoTest::EchoClientSocket::output() {
    int len;

    if (!loops || qflag) {
	write(T(""), 1);
	erase();
	return;
    }
    if (loops != -1)
	loops--;
{'fraction_non_alphanumeric': 0.12279483261564106, 'fraction_numerical': 0.00750104181136269, 'mean_word_length': 4.202312138728324, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '304216', 'n_tokens_mistral': 2488, 'n_tokens_neox': 2346, 'n_words': 722}