2018-09-13 15:22:36 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2018-09-16 03:37:56 -05:00
|
|
|
#include <poll.h>
|
2018-09-13 15:22:36 -05:00
|
|
|
|
2018-10-16 15:56:46 -05:00
|
|
|
#include <cassert>
|
2018-09-15 04:04:05 -05:00
|
|
|
#include <chrono>
|
2018-09-13 15:22:36 -05:00
|
|
|
#include <condition_variable>
|
2018-09-18 07:27:17 -05:00
|
|
|
#include <cstdlib>
|
2018-10-16 15:56:46 -05:00
|
|
|
#include <cstring>
|
2018-09-18 07:27:17 -05:00
|
|
|
#include <iostream>
|
2018-09-16 03:37:56 -05:00
|
|
|
#include <sstream>
|
2018-09-13 15:22:36 -05:00
|
|
|
#include <mutex>
|
2018-09-15 04:04:05 -05:00
|
|
|
#include <thread>
|
2018-09-13 15:22:36 -05:00
|
|
|
#include <vector>
|
|
|
|
|
2018-09-15 15:29:39 -05:00
|
|
|
// A "fake socket" is represented by a number, a smallish integer, just like a real socket.
|
|
|
|
//
|
|
|
|
// There is one FakeSocketPair for each two sequential fake socket numbers. When you create one, you
|
2019-10-08 04:23:29 -05:00
|
|
|
// will always get the lower (even) number in a pair. The higher number will be returned if you
|
|
|
|
// successfully call fakeSocketConnect() from the lower number to some other fake socket.
|
2018-09-15 15:29:39 -05:00
|
|
|
//
|
|
|
|
// After you create a fake socket, there is basically just two things you can do with it:
|
|
|
|
//
|
|
|
|
// 1) Call fakeSocketConnect on it giving another fake socket number to connect to. Once the
|
|
|
|
// connection is successful, you can call fakeSocketRead() and fakeSocketWrite() on your original
|
|
|
|
// socket.
|
|
|
|
//
|
|
|
|
// 2) Call fakeSocketListen() on it, indicating it is a "server" socket. After that, keep calling
|
|
|
|
// fakeSocketAccept() and each time that returns successfully, it will return a new fake socket that
|
|
|
|
// is connected to another fake socket that called fakeSocketConnect() to the server socket. You can
|
|
|
|
// then call fakeSocketRead() and fakeSocketWrite() on it.
|
|
|
|
//
|
|
|
|
// This all is complicated a bit by the fact that all the API is non-blocking.
|
|
|
|
|
2018-09-13 15:22:36 -05:00
|
|
|
struct FakeSocketPair
|
|
|
|
{
|
|
|
|
int fd[2];
|
|
|
|
bool listening;
|
|
|
|
int connectingFd;
|
2018-09-17 12:39:53 -05:00
|
|
|
bool shutdown[2];
|
2018-09-15 15:29:39 -05:00
|
|
|
bool readable[2];
|
2018-10-23 06:50:23 -05:00
|
|
|
std::vector<std::vector<char>> buffer[2];
|
2018-09-13 15:22:36 -05:00
|
|
|
|
|
|
|
FakeSocketPair()
|
|
|
|
{
|
|
|
|
fd[0] = -1;
|
|
|
|
fd[1] = -1;
|
|
|
|
listening = false;
|
2018-09-15 04:04:05 -05:00
|
|
|
connectingFd = -1;
|
2018-09-17 12:39:53 -05:00
|
|
|
shutdown[0] = false;
|
|
|
|
shutdown[1] = false;
|
2018-09-15 15:29:39 -05:00
|
|
|
readable[0] = false;
|
|
|
|
readable[1] = false;
|
2018-09-13 15:22:36 -05:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-16 03:37:56 -05:00
|
|
|
static thread_local std::ostringstream loggingBuffer;
|
|
|
|
static void (*loggingCallback)(const std::string&) = nullptr;
|
|
|
|
|
2018-10-10 02:26:48 -05:00
|
|
|
static std::mutex theMutex;
|
|
|
|
static std::condition_variable theCV;
|
2018-09-13 15:22:36 -05:00
|
|
|
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
static int fakeSocketLogLevel = 0;
|
|
|
|
|
|
|
|
static void fakeSocketDumpStateImpl();
|
|
|
|
|
2018-09-15 04:04:05 -05:00
|
|
|
// Avoid problems with order of initialisation of static globals.
|
|
|
|
static std::vector<FakeSocketPair>& getFds()
|
2018-09-13 15:22:36 -05:00
|
|
|
{
|
2018-09-15 04:04:05 -05:00
|
|
|
static std::vector<FakeSocketPair> fds;
|
2018-09-13 15:22:36 -05:00
|
|
|
|
2018-09-15 04:04:05 -05:00
|
|
|
return fds;
|
|
|
|
}
|
2018-09-13 15:22:36 -05:00
|
|
|
|
2018-09-16 03:37:56 -05:00
|
|
|
static std::string flush()
|
|
|
|
{
|
2018-09-18 07:27:17 -05:00
|
|
|
static bool alwaysStderr = std::getenv("FAKESOCKET_LOG_ALWAYS_STDERR") != nullptr;
|
|
|
|
if (alwaysStderr)
|
2020-05-24 08:10:18 -05:00
|
|
|
std::cerr << std::this_thread::get_id() << ':' << loggingBuffer.str() << std::endl;
|
2018-09-18 07:27:17 -05:00
|
|
|
else if (loggingCallback != nullptr)
|
2018-09-16 03:37:56 -05:00
|
|
|
loggingCallback(loggingBuffer.str());
|
|
|
|
loggingBuffer.str("");
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2019-06-17 16:16:15 -05:00
|
|
|
#ifdef __ANDROID__
|
|
|
|
// kill the verbose logging on Android
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
#define FAKESOCKET_LOG(level, arg)
|
2019-06-17 16:16:15 -05:00
|
|
|
#else
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
#define FAKESOCKET_LOG(level, arg) do { if (level <= fakeSocketLogLevel) { loggingBuffer << arg; } } while (false)
|
2019-06-17 16:16:15 -05:00
|
|
|
#endif
|
|
|
|
|
2018-09-16 03:37:56 -05:00
|
|
|
void fakeSocketSetLoggingCallback(void (*callback)(const std::string&))
|
|
|
|
{
|
|
|
|
loggingCallback = callback;
|
|
|
|
}
|
|
|
|
|
2019-09-30 15:46:09 -05:00
|
|
|
static int fakeSocketAllocate()
|
2018-09-15 04:04:05 -05:00
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
if (fakeSocketLogLevel == 0)
|
|
|
|
{
|
|
|
|
char *logLevel = std::getenv("FAKESOCKET_LOG_LEVEL");
|
|
|
|
if (logLevel == nullptr)
|
|
|
|
fakeSocketLogLevel = 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fakeSocketLogLevel = std::strtol(logLevel, nullptr, 10);
|
|
|
|
if (fakeSocketLogLevel != 1 && fakeSocketLogLevel != 2)
|
|
|
|
fakeSocketLogLevel = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-15 04:04:05 -05:00
|
|
|
std::vector<FakeSocketPair>& fds = getFds();
|
2018-09-13 15:22:36 -05:00
|
|
|
|
2018-10-10 02:26:48 -05:00
|
|
|
std::lock_guard<std::mutex> lock(theMutex);
|
2018-09-15 15:29:39 -05:00
|
|
|
|
|
|
|
// We always allocate a new FakeSocketPair struct. Let's not bother with potential issues with
|
|
|
|
// reusing them. It isn't like we would be allocating thousands anyway during the typical
|
2020-07-07 04:15:37 -05:00
|
|
|
// lifetime of an app. Also, not reusing FakeSocket fd numbers means that it is easier to set a
|
|
|
|
// conditional breakpoint on an operation on a specific fd when debugging some problematic
|
|
|
|
// scenario.
|
2018-09-15 15:29:39 -05:00
|
|
|
|
|
|
|
const int i = fds.size();
|
|
|
|
fds.resize(i + 1);
|
|
|
|
|
2018-09-15 04:04:05 -05:00
|
|
|
FakeSocketPair& result = fds[i];
|
|
|
|
|
|
|
|
result.fd[0] = i*2;
|
|
|
|
|
|
|
|
return i*2;
|
2018-09-13 15:22:36 -05:00
|
|
|
}
|
|
|
|
|
2019-09-30 15:46:09 -05:00
|
|
|
int fakeSocketSocket()
|
|
|
|
{
|
|
|
|
const int result = fakeSocketAllocate();
|
|
|
|
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket Create #" << result << flush());
|
2019-09-30 15:46:09 -05:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2018-09-15 04:04:05 -05:00
|
|
|
int fakeSocketPipe2(int pipefd[2])
|
2018-09-13 15:22:36 -05:00
|
|
|
{
|
2019-09-30 15:46:09 -05:00
|
|
|
pipefd[0] = fakeSocketAllocate();
|
2018-09-15 04:04:05 -05:00
|
|
|
assert(pipefd[0] >= 0);
|
2018-09-13 15:22:36 -05:00
|
|
|
|
2018-09-15 04:04:05 -05:00
|
|
|
std::vector<FakeSocketPair>& fds = getFds();
|
2018-09-13 15:22:36 -05:00
|
|
|
FakeSocketPair& pair = fds[pipefd[0]/2];
|
|
|
|
|
2018-10-10 02:26:48 -05:00
|
|
|
std::unique_lock<std::mutex> lock(theMutex);
|
2018-09-13 15:22:36 -05:00
|
|
|
|
|
|
|
assert(pair.fd[0] == pipefd[0]);
|
|
|
|
|
|
|
|
pair.fd[1] = pair.fd[0] + 1;
|
|
|
|
pipefd[1] = pair.fd[1];
|
|
|
|
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket Pipe created (#" << pipefd[0] << ",#" << pipefd[1] << ')' << flush());
|
2018-09-15 04:04:05 -05:00
|
|
|
|
2018-09-13 15:22:36 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-15 15:29:39 -05:00
|
|
|
static std::string pollBits(int bits)
|
|
|
|
{
|
|
|
|
if (bits == 0)
|
|
|
|
return "-";
|
|
|
|
|
|
|
|
std::string result;
|
|
|
|
|
|
|
|
if (bits & POLLERR)
|
|
|
|
{
|
|
|
|
if (result != "")
|
2020-05-24 08:10:18 -05:00
|
|
|
result += '+';
|
2018-09-15 15:29:39 -05:00
|
|
|
result += "ERR";
|
|
|
|
}
|
|
|
|
if (bits & POLLHUP)
|
|
|
|
{
|
|
|
|
if (result != "")
|
2020-05-24 08:10:18 -05:00
|
|
|
result += '+';
|
2018-09-15 15:29:39 -05:00
|
|
|
result += "HUP";
|
|
|
|
}
|
|
|
|
if (bits & POLLIN)
|
|
|
|
{
|
|
|
|
if (result != "")
|
2020-05-24 08:10:18 -05:00
|
|
|
result += '+';
|
2018-09-15 15:29:39 -05:00
|
|
|
result += "IN";
|
|
|
|
}
|
|
|
|
if (bits & POLLNVAL)
|
|
|
|
{
|
|
|
|
if (result != "")
|
2020-05-24 08:10:18 -05:00
|
|
|
result += '+';
|
2018-09-15 15:29:39 -05:00
|
|
|
result += "NVAL";
|
|
|
|
}
|
|
|
|
if (bits & POLLOUT)
|
|
|
|
{
|
|
|
|
if (result != "")
|
2020-05-24 08:10:18 -05:00
|
|
|
result += '+';
|
2018-09-15 15:29:39 -05:00
|
|
|
result += "OUT";
|
|
|
|
}
|
|
|
|
if (bits & POLLPRI)
|
|
|
|
{
|
|
|
|
if (result != "")
|
2020-05-24 08:10:18 -05:00
|
|
|
result += '+';
|
2018-09-15 15:29:39 -05:00
|
|
|
result += "PRI";
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool checkForPoll(std::vector<FakeSocketPair>& fds, struct pollfd *pollfds, int nfds)
|
2018-09-15 04:04:05 -05:00
|
|
|
{
|
|
|
|
bool retval = false;
|
|
|
|
for (int i = 0; i < nfds; i++)
|
|
|
|
{
|
2018-09-17 12:39:53 -05:00
|
|
|
const int K = ((pollfds[i].fd)&1);
|
|
|
|
const int N = 1 - K;
|
|
|
|
|
2018-11-01 14:26:13 -05:00
|
|
|
if (pollfds[i].fd < 0 || static_cast<unsigned>(pollfds[i].fd/2) >= fds.size())
|
2018-09-17 12:39:53 -05:00
|
|
|
{
|
|
|
|
pollfds[i].revents = POLLNVAL;
|
2018-09-19 09:18:29 -05:00
|
|
|
retval = true;
|
2018-09-17 12:39:53 -05:00
|
|
|
}
|
|
|
|
else
|
2018-09-15 15:29:39 -05:00
|
|
|
{
|
2018-09-17 12:39:53 -05:00
|
|
|
if (fds[pollfds[i].fd/2].fd[K] == -1)
|
2018-09-19 09:18:29 -05:00
|
|
|
{
|
2018-09-17 12:39:53 -05:00
|
|
|
pollfds[i].revents = POLLNVAL;
|
2018-09-19 09:18:29 -05:00
|
|
|
retval = true;
|
|
|
|
}
|
2018-09-17 12:39:53 -05:00
|
|
|
else
|
|
|
|
pollfds[i].revents = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pollfds[i].revents == 0)
|
|
|
|
{
|
2018-09-15 15:29:39 -05:00
|
|
|
if (pollfds[i].events & POLLIN)
|
2018-09-15 04:04:05 -05:00
|
|
|
{
|
2018-09-17 12:39:53 -05:00
|
|
|
if (fds[pollfds[i].fd/2].readable[K] ||
|
|
|
|
(K == 0 && fds[pollfds[i].fd/2].listening && fds[pollfds[i].fd/2].connectingFd != -1))
|
2018-09-15 15:29:39 -05:00
|
|
|
{
|
|
|
|
pollfds[i].revents |= POLLIN;
|
|
|
|
retval = true;
|
|
|
|
}
|
2018-09-15 04:04:05 -05:00
|
|
|
}
|
2018-10-23 06:50:23 -05:00
|
|
|
// With multiple buffers, a socket is always writable unless the peer is closed or shut down
|
2018-09-15 15:29:39 -05:00
|
|
|
if (pollfds[i].events & POLLOUT)
|
|
|
|
{
|
2018-10-23 06:50:23 -05:00
|
|
|
if (fds[pollfds[i].fd/2].fd[N] != -1 && !fds[pollfds[i].fd/2].shutdown[N])
|
2018-09-15 15:29:39 -05:00
|
|
|
{
|
|
|
|
pollfds[i].revents |= POLLOUT;
|
|
|
|
retval = true;
|
|
|
|
}
|
|
|
|
}
|
2020-04-24 02:46:54 -05:00
|
|
|
if (fds[pollfds[i].fd/2].shutdown[N])
|
|
|
|
{
|
|
|
|
pollfds[i].revents |= POLLHUP;
|
|
|
|
retval = true;
|
|
|
|
}
|
2018-09-15 15:29:39 -05:00
|
|
|
}
|
2018-09-15 04:04:05 -05:00
|
|
|
}
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fakeSocketPoll(struct pollfd *pollfds, int nfds, int timeout)
|
2018-09-13 15:22:36 -05:00
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(2, "FakeSocket Poll ");
|
2018-09-15 04:04:05 -05:00
|
|
|
for (int i = 0; i < nfds; i++)
|
|
|
|
{
|
|
|
|
if (i > 0)
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(2, ',');
|
|
|
|
FAKESOCKET_LOG(2, '#' << pollfds[i].fd << ':' << pollBits(pollfds[i].events));
|
2018-09-15 04:04:05 -05:00
|
|
|
}
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(2, ", timeout:" << timeout << flush());
|
2018-09-15 04:04:05 -05:00
|
|
|
|
|
|
|
std::vector<FakeSocketPair>& fds = getFds();
|
2018-10-10 02:26:48 -05:00
|
|
|
std::unique_lock<std::mutex> lock(theMutex);
|
2018-09-15 04:04:05 -05:00
|
|
|
|
2018-09-19 12:01:13 -05:00
|
|
|
if (timeout > 0)
|
|
|
|
{
|
|
|
|
auto const now = std::chrono::steady_clock::now();
|
|
|
|
auto const end = now + std::chrono::milliseconds(timeout);
|
|
|
|
|
|
|
|
while (!checkForPoll(fds, pollfds, nfds))
|
2018-10-10 02:26:48 -05:00
|
|
|
if (theCV.wait_until(lock, end) == std::cv_status::timeout)
|
2018-09-19 12:01:13 -05:00
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(2, "FakeSocket Poll timeout: 0" << flush());
|
2018-09-19 12:01:13 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (timeout == 0)
|
|
|
|
{
|
|
|
|
checkForPoll(fds, pollfds, nfds);
|
|
|
|
}
|
|
|
|
else // timeout < 0
|
|
|
|
{
|
|
|
|
while (!checkForPoll(fds, pollfds, nfds))
|
2018-10-10 02:26:48 -05:00
|
|
|
theCV.wait(lock);
|
2018-09-19 12:01:13 -05:00
|
|
|
}
|
2018-09-15 15:29:39 -05:00
|
|
|
|
2018-09-16 14:37:22 -05:00
|
|
|
int result = 0;
|
|
|
|
for (int i = 0; i < nfds; i++)
|
|
|
|
{
|
|
|
|
if (pollfds[i].revents != 0)
|
|
|
|
result++;
|
|
|
|
}
|
|
|
|
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(2, "FakeSocket Poll result: ");
|
2018-09-15 15:29:39 -05:00
|
|
|
for (int i = 0; i < nfds; i++)
|
|
|
|
{
|
|
|
|
if (i > 0)
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(2, ',');
|
|
|
|
FAKESOCKET_LOG(2, '#' << pollfds[i].fd << ':' << pollBits(pollfds[i].revents));
|
2018-09-15 15:29:39 -05:00
|
|
|
}
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(2, ": " << result << flush());
|
2018-09-15 04:04:05 -05:00
|
|
|
|
2018-09-16 14:37:22 -05:00
|
|
|
return result;
|
2018-09-13 15:22:36 -05:00
|
|
|
}
|
|
|
|
|
2018-09-15 04:04:05 -05:00
|
|
|
int fakeSocketListen(int fd)
|
2018-09-13 15:22:36 -05:00
|
|
|
{
|
2018-09-15 04:04:05 -05:00
|
|
|
std::vector<FakeSocketPair>& fds = getFds();
|
2018-10-10 02:26:48 -05:00
|
|
|
std::unique_lock<std::mutex> lock(theMutex);
|
2018-11-01 14:26:13 -05:00
|
|
|
if (fd < 0 || static_cast<unsigned>(fd/2) >= fds.size() || fds[fd/2].fd[fd&1] == -1)
|
2018-09-13 15:22:36 -05:00
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket EBADF: Listening on #" << fd << flush());
|
2018-09-13 15:22:36 -05:00
|
|
|
errno = EBADF;
|
|
|
|
return -1;
|
|
|
|
}
|
2019-10-08 04:23:29 -05:00
|
|
|
|
2018-09-13 15:22:36 -05:00
|
|
|
FakeSocketPair& pair = fds[fd/2];
|
|
|
|
|
|
|
|
if (fd&1 || pair.fd[1] != -1)
|
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket EISCONN: Listening on #" << fd << flush());
|
2018-09-13 15:22:36 -05:00
|
|
|
errno = EISCONN;
|
|
|
|
return -1;
|
|
|
|
}
|
2019-10-08 04:23:29 -05:00
|
|
|
|
2018-09-13 15:22:36 -05:00
|
|
|
if (pair.listening)
|
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket EIO: Listening on #" << fd << flush());
|
2018-09-13 15:22:36 -05:00
|
|
|
errno = EIO;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pair.listening = true;
|
|
|
|
pair.connectingFd = -1;
|
|
|
|
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket Listen #" << fd << flush());
|
2018-09-15 04:04:05 -05:00
|
|
|
|
2018-09-13 15:22:36 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fakeSocketConnect(int fd1, int fd2)
|
|
|
|
{
|
2018-09-15 04:04:05 -05:00
|
|
|
std::vector<FakeSocketPair>& fds = getFds();
|
2018-10-10 02:26:48 -05:00
|
|
|
std::unique_lock<std::mutex> lock(theMutex);
|
2018-11-01 14:26:13 -05:00
|
|
|
if (fd1 < 0 || fd2 < 0 || static_cast<unsigned>(fd1/2) >= fds.size() || static_cast<unsigned>(fd2/2) >= fds.size())
|
2018-09-13 15:22:36 -05:00
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket EBADF: Connect #" << fd1 << " to #" << fd2 << flush());
|
2018-09-13 15:22:36 -05:00
|
|
|
errno = EBADF;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (fd1/2 == fd2/2)
|
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket EBADF: Connect #" << fd1 << " to #" << fd2 << flush());
|
2018-09-13 15:22:36 -05:00
|
|
|
errno = EBADF;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
FakeSocketPair& pair1 = fds[fd1/2];
|
|
|
|
FakeSocketPair& pair2 = fds[fd2/2];
|
|
|
|
|
|
|
|
if ((fd1&1) || (fd2&1))
|
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket EISCONN: Connect #" << fd1 << " to #" << fd2 << flush());
|
2018-09-13 15:22:36 -05:00
|
|
|
errno = EISCONN;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!pair2.listening || pair2.connectingFd != -1)
|
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket ECONNREFUSED: Connect #" << fd1 << " to #" << fd2 << flush());
|
2018-09-13 15:22:36 -05:00
|
|
|
errno = ECONNREFUSED;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pair2.connectingFd = fd1;
|
2018-10-10 02:26:48 -05:00
|
|
|
theCV.notify_all();
|
2018-09-15 15:29:39 -05:00
|
|
|
|
2018-09-13 15:22:36 -05:00
|
|
|
while (pair1.fd[1] == -1)
|
2018-10-10 02:26:48 -05:00
|
|
|
theCV.wait(lock);
|
2018-09-13 15:22:36 -05:00
|
|
|
|
|
|
|
assert(pair1.fd[1] == pair1.fd[0] + 1);
|
|
|
|
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket Connect #" << fd1 << " to #" << fd2 << ": #" << pair1.fd[1] << flush());
|
2018-09-15 04:04:05 -05:00
|
|
|
|
2018-09-13 15:22:36 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-11-01 14:29:40 -05:00
|
|
|
int fakeSocketAccept4(int fd)
|
2018-09-13 15:22:36 -05:00
|
|
|
{
|
2018-09-15 04:04:05 -05:00
|
|
|
std::vector<FakeSocketPair>& fds = getFds();
|
2018-10-10 02:26:48 -05:00
|
|
|
std::unique_lock<std::mutex> lock(theMutex);
|
2018-11-01 14:26:13 -05:00
|
|
|
if (fd < 0 || static_cast<unsigned>(fd/2) >= fds.size())
|
2018-09-13 15:22:36 -05:00
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket EBADF: Accept #" << fd << flush());
|
2018-09-13 15:22:36 -05:00
|
|
|
errno = EBADF;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fd & 1)
|
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket EISCONN: Accept #" << fd << flush());
|
2018-09-13 15:22:36 -05:00
|
|
|
errno = EISCONN;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
FakeSocketPair& pair = fds[fd/2];
|
|
|
|
|
|
|
|
if (!pair.listening)
|
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket EIO: Accept #" << fd << flush());
|
2018-09-13 15:22:36 -05:00
|
|
|
errno = EIO;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (pair.connectingFd == -1)
|
2018-10-10 02:26:48 -05:00
|
|
|
theCV.wait(lock);
|
2019-10-08 04:23:29 -05:00
|
|
|
|
2018-10-10 02:26:48 -05:00
|
|
|
assert(pair.connectingFd >= 0);
|
2018-11-01 14:26:13 -05:00
|
|
|
assert(static_cast<unsigned>(pair.connectingFd/2) < fds.size());
|
2018-10-10 02:26:48 -05:00
|
|
|
assert((pair.connectingFd&1) == 0);
|
2018-09-13 15:22:36 -05:00
|
|
|
|
2018-09-15 15:29:39 -05:00
|
|
|
FakeSocketPair& pair2 = fds[pair.connectingFd/2];
|
2019-10-08 04:23:29 -05:00
|
|
|
|
2018-09-15 15:29:39 -05:00
|
|
|
assert(pair2.fd[1] == -1);
|
|
|
|
assert(pair2.fd[0] == pair.connectingFd);
|
2018-09-13 15:22:36 -05:00
|
|
|
|
|
|
|
pair.connectingFd = -1;
|
|
|
|
|
2018-09-15 15:29:39 -05:00
|
|
|
pair2.fd[1] = pair2.fd[0] + 1;
|
2018-09-13 15:22:36 -05:00
|
|
|
|
2018-10-10 02:26:48 -05:00
|
|
|
theCV.notify_all();
|
2018-09-15 04:04:05 -05:00
|
|
|
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket Accept #" << fd << ": #" << pair2.fd[1] << flush());
|
|
|
|
|
|
|
|
fakeSocketDumpStateImpl();
|
2018-09-13 15:22:36 -05:00
|
|
|
|
2018-09-15 15:29:39 -05:00
|
|
|
return pair2.fd[1];
|
2018-09-13 15:22:36 -05:00
|
|
|
}
|
|
|
|
|
2018-09-15 04:04:05 -05:00
|
|
|
int fakeSocketPeer(int fd)
|
|
|
|
{
|
|
|
|
std::vector<FakeSocketPair>& fds = getFds();
|
2018-10-10 02:26:48 -05:00
|
|
|
std::unique_lock<std::mutex> lock(theMutex);
|
2018-11-01 14:26:13 -05:00
|
|
|
if (fd < 0 || static_cast<unsigned>(fd/2) >= fds.size())
|
2018-09-15 04:04:05 -05:00
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket EBADF: Peer of #" << fd << flush());
|
2018-09-15 04:04:05 -05:00
|
|
|
errno = EBADF;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
FakeSocketPair& pair = fds[fd/2];
|
|
|
|
|
|
|
|
const int K = (fd&1);
|
|
|
|
const int N = 1 - K;
|
|
|
|
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket Peer of #" << fd << ": #" << pair.fd[N] << flush());
|
2018-09-16 14:37:22 -05:00
|
|
|
|
2018-09-15 04:04:05 -05:00
|
|
|
return pair.fd[N];
|
|
|
|
}
|
|
|
|
|
2018-09-14 02:49:58 -05:00
|
|
|
ssize_t fakeSocketAvailableDataLength(int fd)
|
|
|
|
{
|
2018-09-15 04:04:05 -05:00
|
|
|
std::vector<FakeSocketPair>& fds = getFds();
|
2018-10-10 02:26:48 -05:00
|
|
|
std::unique_lock<std::mutex> lock(theMutex);
|
2018-11-01 14:26:13 -05:00
|
|
|
if (fd < 0 || static_cast<unsigned>(fd/2) >= fds.size())
|
2018-09-14 02:49:58 -05:00
|
|
|
{
|
|
|
|
errno = EBADF;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
FakeSocketPair& pair = fds[fd/2];
|
|
|
|
|
|
|
|
// K: for this fd
|
|
|
|
const int K = (fd&1);
|
|
|
|
|
2018-09-15 15:29:39 -05:00
|
|
|
if (!pair.readable[K])
|
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(2, "FakeSocket EAGAIN: Available data on #" << fd << flush());
|
2018-09-15 15:29:39 -05:00
|
|
|
errno = EAGAIN;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-10-25 13:53:34 -05:00
|
|
|
ssize_t result = 0;
|
|
|
|
if (pair.buffer[K].size() > 0)
|
|
|
|
result = pair.buffer[K][0].size();
|
2018-09-15 15:29:39 -05:00
|
|
|
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(2, "FakeSocket Available data on #" << fd << ": " << result << flush());
|
2018-10-25 13:53:34 -05:00
|
|
|
|
|
|
|
return result;
|
2018-09-14 02:49:58 -05:00
|
|
|
}
|
|
|
|
|
2018-09-13 15:22:36 -05:00
|
|
|
ssize_t fakeSocketRead(int fd, void *buf, size_t nbytes)
|
|
|
|
{
|
2018-09-15 04:04:05 -05:00
|
|
|
std::vector<FakeSocketPair>& fds = getFds();
|
2018-10-10 02:26:48 -05:00
|
|
|
std::unique_lock<std::mutex> lock(theMutex);
|
2018-11-01 14:26:13 -05:00
|
|
|
if (fd < 0 || static_cast<unsigned>(fd/2) >= fds.size())
|
2018-09-13 15:22:36 -05:00
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(2, "FakeSocket EBADF: Read from #" << fd << ", " << nbytes << (nbytes == 1 ? " byte" : " bytes") << flush());
|
2018-09-13 15:22:36 -05:00
|
|
|
errno = EBADF;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
FakeSocketPair& pair = fds[fd/2];
|
|
|
|
|
|
|
|
// K: for this fd
|
|
|
|
const int K = (fd&1);
|
2018-09-15 15:29:39 -05:00
|
|
|
// N: for its peer
|
|
|
|
const int N = 1 - K;
|
2018-09-13 15:22:36 -05:00
|
|
|
|
2018-09-15 04:04:05 -05:00
|
|
|
if (pair.fd[K] == -1)
|
2018-09-13 15:22:36 -05:00
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(2, "FakeSocket EBADF: Read from #" << fd << ", " << nbytes << (nbytes == 1 ? " byte" : " bytes") << flush());
|
2018-09-15 04:04:05 -05:00
|
|
|
errno = EBADF;
|
|
|
|
return -1;
|
2018-09-13 15:22:36 -05:00
|
|
|
}
|
|
|
|
|
2018-09-17 12:39:53 -05:00
|
|
|
if (pair.shutdown[K])
|
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(2, "FakeSocket Read from #" << fd << " (shut down) got 0 bytes" << flush());
|
2018-09-18 03:34:15 -05:00
|
|
|
return 0;
|
2018-09-17 12:39:53 -05:00
|
|
|
}
|
|
|
|
|
2018-09-15 15:29:39 -05:00
|
|
|
if (!pair.readable[K])
|
2018-09-15 04:04:05 -05:00
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(2, "FakeSocket EAGAIN: Read from #" << fd << ", " << nbytes << (nbytes == 1 ? " byte" : " bytes") << flush());
|
2018-09-15 04:04:05 -05:00
|
|
|
errno = EAGAIN;
|
|
|
|
return -1;
|
2018-09-13 15:22:36 -05:00
|
|
|
}
|
|
|
|
|
2018-10-29 17:46:52 -05:00
|
|
|
ssize_t result = 0;
|
|
|
|
if (pair.buffer[K].size() > 0)
|
2018-09-14 02:49:58 -05:00
|
|
|
{
|
2018-10-29 17:46:52 -05:00
|
|
|
// These sockets are record-oriented. It won't work to read less than the whole record in
|
|
|
|
// turn to be read.
|
|
|
|
result = pair.buffer[K][0].size();
|
2018-11-01 14:26:13 -05:00
|
|
|
if (nbytes < static_cast<unsigned>(result))
|
2018-10-29 17:46:52 -05:00
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(2, "FakeSocket EAGAIN: Read from #" << fd << ", " << nbytes << (nbytes == 1 ? " byte" : " bytes") << flush());
|
2018-10-29 17:46:52 -05:00
|
|
|
errno = EAGAIN; // Not the right errno, but what would be?
|
|
|
|
return -1;
|
|
|
|
}
|
2018-09-13 15:22:36 -05:00
|
|
|
|
2018-10-29 17:46:52 -05:00
|
|
|
memmove(buf, pair.buffer[K][0].data(), result);
|
|
|
|
pair.buffer[K].erase(pair.buffer[K].begin());
|
|
|
|
}
|
2018-10-23 06:50:23 -05:00
|
|
|
|
2018-09-17 12:39:53 -05:00
|
|
|
// If peer is closed or shut down, we continue to be readable
|
|
|
|
if (pair.fd[N] == -1 || pair.shutdown[N])
|
2018-09-15 15:29:39 -05:00
|
|
|
pair.readable[K] = true;
|
2023-03-04 14:53:45 -06:00
|
|
|
else if (pair.buffer[K].empty())
|
2018-09-15 15:29:39 -05:00
|
|
|
pair.readable[K] = false;
|
2018-09-13 15:22:36 -05:00
|
|
|
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(2, "FakeSocket Read from #" << fd << " got " << result << (result == 1 ? " byte" : " bytes") << flush());
|
2018-09-13 15:22:36 -05:00
|
|
|
|
2018-09-14 02:49:58 -05:00
|
|
|
return result;
|
2018-09-13 15:22:36 -05:00
|
|
|
}
|
|
|
|
|
2018-09-17 12:39:53 -05:00
|
|
|
ssize_t fakeSocketWrite(int fd, const void *buf, size_t nbytes)
|
2018-09-15 04:04:05 -05:00
|
|
|
{
|
|
|
|
std::vector<FakeSocketPair>& fds = getFds();
|
2018-10-10 02:26:48 -05:00
|
|
|
std::unique_lock<std::mutex> lock(theMutex);
|
2018-11-01 14:26:13 -05:00
|
|
|
if (fd < 0 || static_cast<unsigned>(fd/2) >= fds.size())
|
2018-09-15 04:04:05 -05:00
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(2, "FakeSocket EBADF: Write to #" << fd << ", " << nbytes << (nbytes == 1 ? " byte" : " bytes") << flush());
|
2018-09-15 04:04:05 -05:00
|
|
|
errno = EBADF;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
FakeSocketPair& pair = fds[fd/2];
|
|
|
|
|
2018-09-17 12:39:53 -05:00
|
|
|
// K: for this fd
|
|
|
|
// N: for its peer, whose read buffer we want to write into
|
2018-09-15 04:04:05 -05:00
|
|
|
const int K = (fd&1);
|
2018-09-17 12:39:53 -05:00
|
|
|
const int N = 1 - K;
|
2018-09-15 04:04:05 -05:00
|
|
|
|
|
|
|
if (pair.fd[K] == -1)
|
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(2, "FakeSocket EBADF: Write to #" << fd << ", " << nbytes << (nbytes == 1 ? " byte" : " bytes") << flush());
|
2018-09-17 12:39:53 -05:00
|
|
|
errno = EBADF;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pair.shutdown[K])
|
|
|
|
{
|
2018-09-18 03:34:15 -05:00
|
|
|
// Should we raise(SIGPIPE)? Probably not, Online code does not expect SIGPIPE at all...
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(2, "FakeSocket EPIPE: Write to #" << fd << " (shut down), " << nbytes << (nbytes == 1 ? " byte" : " bytes") << flush());
|
2018-09-18 03:34:15 -05:00
|
|
|
errno = EPIPE;
|
2018-09-15 04:04:05 -05:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-10-23 06:50:23 -05:00
|
|
|
pair.buffer[N].emplace_back(std::vector<char>(nbytes));
|
|
|
|
memmove(pair.buffer[N].back().data(), buf, nbytes);
|
2018-09-17 12:39:53 -05:00
|
|
|
pair.readable[N] = true;
|
2018-09-15 04:04:05 -05:00
|
|
|
|
2018-10-10 02:26:48 -05:00
|
|
|
theCV.notify_all();
|
2018-09-15 04:04:05 -05:00
|
|
|
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(2, "FakeSocket Write to #" << fd << ": " << nbytes << (nbytes == 1 ? " byte" : " bytes") << flush());
|
2018-09-15 04:04:05 -05:00
|
|
|
return nbytes;
|
|
|
|
}
|
|
|
|
|
2018-09-17 12:39:53 -05:00
|
|
|
int fakeSocketShutdown(int fd)
|
2018-09-13 15:22:36 -05:00
|
|
|
{
|
2018-09-15 04:04:05 -05:00
|
|
|
std::vector<FakeSocketPair>& fds = getFds();
|
2018-10-10 02:26:48 -05:00
|
|
|
std::unique_lock<std::mutex> lock(theMutex);
|
2018-11-01 14:26:13 -05:00
|
|
|
if (fd < 0 || static_cast<unsigned>(fd/2) >= fds.size())
|
2018-09-13 15:22:36 -05:00
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket EBADF: Shutdown #" << fd << flush());
|
2018-09-13 15:22:36 -05:00
|
|
|
errno = EBADF;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
FakeSocketPair& pair = fds[fd/2];
|
|
|
|
|
|
|
|
const int K = (fd&1);
|
|
|
|
const int N = 1 - K;
|
|
|
|
|
2018-09-15 04:04:05 -05:00
|
|
|
if (pair.fd[K] == -1)
|
2018-09-13 15:22:36 -05:00
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket EBADF: Shutdown #" << fd << flush());
|
2018-09-15 04:04:05 -05:00
|
|
|
errno = EBADF;
|
|
|
|
return -1;
|
2018-09-13 15:22:36 -05:00
|
|
|
}
|
|
|
|
|
2018-09-17 12:39:53 -05:00
|
|
|
if (pair.fd[N] == -1)
|
2018-09-15 04:04:05 -05:00
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket ENOTCONN: Shutdown #" << fd << flush());
|
2018-09-17 12:39:53 -05:00
|
|
|
errno = ENOTCONN;
|
2018-09-15 04:04:05 -05:00
|
|
|
return -1;
|
2018-09-13 15:22:36 -05:00
|
|
|
}
|
|
|
|
|
2018-09-17 12:39:53 -05:00
|
|
|
pair.shutdown[K] = true;
|
|
|
|
pair.readable[K] = true;
|
2018-09-13 15:22:36 -05:00
|
|
|
|
2020-07-07 04:41:13 -05:00
|
|
|
theCV.notify_all();
|
|
|
|
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket Shutdown #" << fd << flush());
|
2018-09-13 15:22:36 -05:00
|
|
|
|
2018-09-17 12:39:53 -05:00
|
|
|
return 0;
|
2018-09-13 15:22:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
int fakeSocketClose(int fd)
|
|
|
|
{
|
2018-09-15 04:04:05 -05:00
|
|
|
std::vector<FakeSocketPair>& fds = getFds();
|
2018-10-10 02:26:48 -05:00
|
|
|
std::unique_lock<std::mutex> lock(theMutex);
|
2018-11-01 14:26:13 -05:00
|
|
|
if (fd < 0 || static_cast<unsigned>(fd/2) >= fds.size())
|
2018-09-13 15:22:36 -05:00
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket EBADF: Close #" << fd << flush());
|
2018-09-13 15:22:36 -05:00
|
|
|
errno = EBADF;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
FakeSocketPair& pair = fds[fd/2];
|
|
|
|
|
2018-09-15 15:29:39 -05:00
|
|
|
const int K = (fd&1);
|
|
|
|
const int N = 1 - K;
|
|
|
|
|
2018-09-17 12:39:53 -05:00
|
|
|
if (pair.fd[K] == -1)
|
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket EBADF: Close #" << fd << flush());
|
2018-09-17 12:39:53 -05:00
|
|
|
errno = EBADF;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-09-15 15:29:39 -05:00
|
|
|
assert(pair.fd[K] == fd);
|
2018-09-13 15:22:36 -05:00
|
|
|
|
2018-09-15 15:29:39 -05:00
|
|
|
pair.fd[K] = -1;
|
|
|
|
pair.buffer[K].resize(0);
|
|
|
|
pair.readable[N] = true;
|
|
|
|
|
2018-10-10 02:26:48 -05:00
|
|
|
theCV.notify_all();
|
2018-09-13 15:22:36 -05:00
|
|
|
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket Close #" << fd << flush());
|
|
|
|
|
|
|
|
fakeSocketDumpStateImpl();
|
2018-09-15 04:04:05 -05:00
|
|
|
|
2018-09-13 15:22:36 -05:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
static void fakeSocketDumpStateImpl()
|
2018-10-15 14:41:38 -05:00
|
|
|
{
|
|
|
|
std::vector<FakeSocketPair>& fds = getFds();
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, "FakeSocket open sockets:" << flush());
|
2018-11-01 14:26:13 -05:00
|
|
|
for (int i = 0; i < static_cast<int>(fds.size()); i++)
|
2018-10-15 14:41:38 -05:00
|
|
|
{
|
|
|
|
if (fds[i].fd[0] != -1)
|
|
|
|
{
|
|
|
|
assert(fds[i].fd[0] == i*2);
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, " #" << fds[i].fd[0]);
|
2018-10-15 14:41:38 -05:00
|
|
|
if (fds[i].fd[1] != -1)
|
|
|
|
{
|
|
|
|
assert(fds[i].fd[1] == i*2+1);
|
|
|
|
assert(!fds[i].listening);
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, " <=> #" << fds[i].fd[1]);
|
2018-10-15 14:41:38 -05:00
|
|
|
}
|
|
|
|
else if (fds[i].listening)
|
|
|
|
{
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, " listening");
|
2018-10-15 14:41:38 -05:00
|
|
|
}
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, flush());
|
2018-10-15 14:41:38 -05:00
|
|
|
}
|
|
|
|
else if (fds[i].fd[1] != -1)
|
|
|
|
{
|
|
|
|
assert(fds[i].fd[1] == i*2+1);
|
|
|
|
assert(!fds[i].listening);
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
FAKESOCKET_LOG(1, " #" << fds[i].fd[1] << flush());
|
2018-10-15 14:41:38 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Introduce more selective FakeSocket logging
Set a FAKESOCKET_LOG_LEVEL environment variable to "2" for more
verbose logging. This is how it used to be, and is indeed very
verbose, as each poll, read, and write operation is logged.
(Normally the FakeSocket logging does not get displayed, though, as it
is passed to LOG_INF() and the default LOOL_LOGLEVEL is "warning". To
see it, either set FAKESOCKET_LOG_ALWAYS_STDERR or set LOOL_LOGLEVEL
appropriately.)
With the default log level 1 only creation, connection, and closing of
FakeSockets is logged, and the state of all active ones is displayed
after each established connetion and when a FakeSocket has been
closed. This is usually enough to get a basic trace of how the
plumbing works.
Change-Id: Id87bd32ce06105af561aa6a75cf365b41c079713
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96943
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
2020-06-23 07:29:43 -05:00
|
|
|
void fakeSocketDumpState()
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lock(theMutex);
|
|
|
|
fakeSocketDumpStateImpl();
|
|
|
|
}
|
|
|
|
|
2018-09-13 15:22:36 -05:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|