27 if (ZSTD_isError(
n)) {
39 m_keySet <<
"cliendId"_L1
42 <<
"sessionTracepoints"_L1
45 <<
"compressionScheme"_L1;
51 ZSTD_freeCCtx(m_zstdCCtx);
82 return m_bufferOnIdle;
90void QCtfServer::setStatusAndNotify(ServerStatus status)
98 m_writtenSize +=
size;
99 if (m_writtenSize >= m_waitWriteSize && m_eventLoop)
103void QCtfServer::initWrite()
109bool QCtfServer::waitSocket()
134 m_currentKey = readString(cbor);
136 switch (m_keySet.
indexOf(m_currentKey)) {
144 m_requestedCompressionScheme = readString(cbor);
150 m_currentKey.
clear();
162 switch (m_keySet.
indexOf(m_currentKey)) {
187 m_currentKey.
clear();
192 switch (cbor.
type()) {
199 handleFixedWidth(cbor);
229 if (m_compression > 0) {
246bool QCtfServer::recognizedCompressionScheme()
const
248 if (m_requestedCompressionScheme.
isEmpty())
268 qCInfo(lcCtfInfoTrace) <<
"Starting CTF server: " << m_address <<
", port: " << m_port;
270 while (m_stopping == 0) {
273 qCInfo(lcCtfInfoTrace) <<
"Unable to start server";
275 setStatusAndNotify(
Error);
278 setStatusAndNotify(
Idle);
280 qCInfo(lcCtfInfoTrace) <<
"client connection";
285 if (m_eventLoop) m_eventLoop->
exit();
289 if (m_eventLoop) m_eventLoop->
exit();
304 qCInfo(lcCtfInfoTrace) <<
"Invalid trace request.";
309 m_compression =
qMin(m_compression, ZSTD_maxCLevel());
311 m_compression =
qMin(m_compression, 9);
317 if (!recognizedCompressionScheme()) {
318 qCWarning(lcCtfInfoTrace) <<
"Client requested unrecognized compression scheme: " << m_requestedCompressionScheme;
319 m_requestedCompressionScheme.
clear();
329 resp.serverVersion = 1;
333 cbor.
startMap(m_compression ? 4 : 3);
334 cbor.
append(
"serverId"_L1);
335 cbor.
append(resp.serverId);
336 cbor.
append(
"serverVersion"_L1);
337 cbor.
append(resp.serverVersion);
338 cbor.
append(
"serverName"_L1);
339 cbor.
append(resp.serverName);
341 cbor.
append(
"compressionScheme"_L1);
342 cbor.
append(m_requestedCompressionScheme);
347 qCInfo(lcCtfInfoTrace) <<
"response sent, sending data";
350 QList<TracePacket> packets;
353 while (m_packets.
size() == 0)
354 m_bufferHasData.
wait(&m_mutex);
355 packets = std::exchange(m_packets, {});
361 writePacket(packet, cbor);
366 qCInfo(lcCtfInfoTrace) << packets.size() <<
" packets written";
370 qCInfo(lcCtfInfoTrace) <<
"client connection closed";
374 m_eventLoop =
nullptr;
378 setStatusAndNotify(
Error);
389 this->m_stopping = 1;
401 if (m_packets.
size() > m_maxPackets)
void close() override
Closes the I/O device for the socket and calls disconnectFromHost() to close the socket's connection.
SocketState state() const
Returns the state of the socket.
void disconnected()
This signal is emitted when the socket has been disconnected.
char * data()
\macro QT_NO_CAST_FROM_BYTEARRAY
void truncate(qsizetype pos)
Truncates the byte array at index position pos.
\inmodule QtCore\reentrant
QCborError lastError() const
Returns the last error in decoding the stream, if any.
bool next(int maxRecursion=10000)
Advance the CBOR stream decoding one element.
Type type() const
\variable QCborStreamReader::StringResult::data
bool enterContainer()
Enters the array or map that is the current item and prepares for iterating the elements contained in...
bool isUnsignedInteger() const
Returns true if the type of the current element is an unsigned integer (that is if type() returns QCb...
void reparse()
Reparses the current element.
StringResult< QString > readString()
Decodes one string chunk from the CBOR string and returns it.
bool hasNext() const noexcept Q_DECL_PURE_FUNCTION
Returns true if there are more items to be decoded in the current container or false of we've reached...
quint64 toUnsignedInteger() const
Returns the unsigned integer value of the current element.
bool leaveContainer()
Leaves the array or map whose items were being processed and positions the decoder at the next item a...
\inmodule QtCore\reentrant
bool endMap()
Terminates the map started by either overload of startMap() and returns true if the correct number of...
void startMap()
Starts a CBOR Map with indeterminate length in the CBOR stream.
void append(quint64 u)
This is an overloaded member function, provided for convenience. It differs from the above function o...
void setHost(const QString &address)
QString sessionTracepoints() const
QCtfServer(QObject *parent=nullptr)
@ RequestSessionTracepoints
@ RequestCompressionScheme
bool bufferOnIdle() const
void setCallback(ServerCallback *cb)
void bufferData(const QString &stream, const QByteArray &data, quint32 flags)
ServerStatus status() const
QString sessionName() const
int exec(ProcessEventsFlags flags=AllEvents)
Enters the main event loop and waits until exit() is called.
void exit(int returnCode=0)
Tells the event loop to exit with a return code.
The QHostAddress class provides an IP address.
void readyRead()
This signal is emitted once every time new data is available for reading from the device's current re...
void bytesWritten(qint64 bytes)
This signal is emitted every time a payload of data has been written to the device's current write ch...
qsizetype size() const noexcept
void pop_front() noexcept
void append(parameter_type t)
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
void clear()
Clears the contents of the string and makes it null.
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
The QTcpServer class provides a TCP-based server.
QString errorString() const
Returns a human readable description of the last error that occurred.
virtual QTcpSocket * nextPendingConnection()
Returns the next pending connection as a connected QTcpSocket object.
bool listen(const QHostAddress &address=QHostAddress::Any, quint16 port=0)
Tells the server to listen for incoming connections on address address and port port.
bool isListening() const
Returns true if the server is currently listening for incoming connections; otherwise returns false.
bool waitForNewConnection(int msec=0, bool *timedOut=nullptr)
Waits for at most msec milliseconds or until an incoming connection is available.
void close()
Closes the server.
bool wait(QDeadlineTimer deadline=QDeadlineTimer(QDeadlineTimer::Forever))
bool wait(QMutex *, QDeadlineTimer=QDeadlineTimer(QDeadlineTimer::Forever))
constexpr Initialization Uninitialized
QByteArray qCompress(const uchar *data, qsizetype nbytes, int compressionLevel)
struct ZSTD_CCtx_s ZSTD_CCtx
#define Q_LOGGING_CATEGORY(name,...)
#define qCInfo(category,...)
#define qCWarning(category,...)
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLuint GLuint64EXT address
SSL_CTX int(* cb)(SSL *ssl, unsigned char **out, unsigned char *outlen, const unsigned char *in, unsigned int inlen, void *arg)
#define QStringLiteral(str)
virtual void handleSessionChange()=0
virtual void handleStatusChange(ServerStatus status)=0
qsizetype indexOf(const AT &t, qsizetype from=0) const noexcept
static constexpr quint32 PacketSize
static constexpr quint32 PacketMagicNumber
QString sessionTracepoints