src/relpipe-out-socket.cpp
author František Kučera <franta-hg@frantovo.cz>
Thu, 18 Aug 2022 03:39:55 +0200
branchv_0
changeset 22 9a7c42cca24b
parent 0 924e354948df
permissions -rw-r--r--
SCTP: sendmsg()
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
/**
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
 * Relational pipes
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
 * Copyright © 2022 František Kučera (Frantovo.cz, GlobalCode.info)
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
 *
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
 * This program is free software: you can redistribute it and/or modify
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License as published by
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
 * the Free Software Foundation, version 3 of the License.
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
 *
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * GNU General Public License for more details.
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 *
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
 */
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
#include <cstdlib>
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
#include <memory>
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
#include <relpipe/cli/CLI.h>
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
#include <relpipe/cli/RelpipeCLIException.h>
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
#include <relpipe/reader/Factory.h>
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
#include <relpipe/reader/RelationalReader.h>
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
#include <relpipe/reader/RelpipeReaderException.h>
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
#include "SocketHandler.h"
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
#include "CLIParser.h"
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
#include "Configuration.h"
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
using namespace relpipe::cli;
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
using namespace relpipe::reader;
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
using namespace relpipe::out::socket;
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
int main(int argc, char**argv) {
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
	setlocale(LC_ALL, "");
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
	CLI::untieStdIO();
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    39
	CLI cli(argc, argv);
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    40
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    41
	int resultCode = CLI::EXIT_CODE_UNEXPECTED_ERROR;
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    42
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    43
	try {
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    44
		CLIParser cliParser;
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    45
		Configuration configuration = cliParser.parse(cli.arguments());
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    46
		std::shared_ptr<RelationalReader> reader(Factory::create(std::cin));
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    47
		SocketHandler handler(configuration);
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    48
		reader->addHandler(&handler);
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    49
		reader->process();
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    50
		resultCode = CLI::EXIT_CODE_SUCCESS;
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    51
	} catch (RelpipeCLIException e) {
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    52
		fwprintf(stderr, L"Caught CLI exception: %ls\n", e.getMessage().c_str());
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    53
		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    54
		resultCode = e.getExitCode();
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    55
	} catch (RelpipeReaderException e) {
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
		fwprintf(stderr, L"Caught Reader exception: %ls\n", e.getMessage().c_str());
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    57
		fwprintf(stderr, L"Debug: Input stream: eof=%ls, lastRead=%d\n", (cin.eof() ? L"true" : L"false"), cin.gcount());
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
		resultCode = CLI::EXIT_CODE_DATA_ERROR;
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
	}
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    60
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    61
	return resultCode;
924e354948df establish project
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
}