87#ifdef QSCTPSOCKET_DEBUG
96 : maximumChannelCount(0)
111#if defined (QSCTPSOCKET_DEBUG)
112 qDebug(
"QSctpSocketPrivate::canReadNotification()");
116 if (!
q->isInDatagramMode())
120 bool currentChannelRead =
false;
128 if (bytesToRead == 0) {
138#if defined (QSCTPSOCKET_DEBUG)
139 qDebug(
"QSctpSocketPrivate::canReadNotification() about to read %lli bytes",
145 if (readBytes <= 0) {
146 if (readBytes == -2) {
148 return currentChannelRead;
152 if (readBytes == 0) {
154 QSctpSocket::tr(
"The remote host closed the connection"));
156#if defined (QSCTPSOCKET_DEBUG)
157 qDebug(
"QSctpSocketPrivate::canReadNotification() read failed: %s",
163#if defined (QSCTPSOCKET_DEBUG)
164 qDebug(
"QSctpSocketPrivate::canReadNotification() disconnecting socket");
166 q->disconnectFromHost();
167 return currentChannelRead;
169 datagramSize += int(readBytes);
170 }
while (!
header.endOfRecord);
172#if defined (QSCTPSOCKET_DEBUG)
173 qDebug(
"QSctpSocketPrivate::canReadNotification() got datagram from channel %i, size = %i",
174 header.streamNumber, datagramSize);
178 if (!
q->isReadable()) {
195 if (
header.streamNumber == savedCurrentChannel)
196 currentChannelRead =
true;
201 return currentChannelRead;
209#if defined (QSCTPSOCKET_DEBUG)
210 qDebug(
"QSctpSocketPrivate::writeToSocket()");
214 if (!
q->isInDatagramMode())
222 bool currentChannelWritten =
false;
225 transmitting =
false;
230 if (channelBuffer.isEmpty())
238 channelBuffer.nextDataBlockSize(),
242 return currentChannelWritten;
245#if defined (QSCTPSOCKET_DEBUG)
246 qDebug(
"QSctpSocketPrivate::writeToSocket() write error, aborting. %s",
251 q->disconnectFromHost();
252 return currentChannelWritten;
254 Q_ASSERT(sent == channelBuffer.nextDataBlockSize());
255#if defined (QSCTPSOCKET_DEBUG)
256 qDebug(
"QSctpSocketPrivate::writeToSocket() sent datagram of size %lli to channel %i",
262 channelBuffer.read();
267 if (
channel == savedCurrentChannel)
268 currentChannelWritten =
true;
273#if defined (QSCTPSOCKET_DEBUG)
274 qDebug(
"QSctpSocketPrivate::writeToSocket() socket is closing - returning");
276 return currentChannelWritten;
279 }
while (transmitting);
284 q->disconnectFromHost();
288 return currentChannelWritten;
311#if defined(QSCTPSOCKET_DEBUG)
312 qDebug(
"QSctpSocket::QSctpSocket()");
314 d_func()->isBuffered =
true;
324#if defined(QSCTPSOCKET_DEBUG)
325 qDebug(
"QSctpSocket::~QSctpSocket()");
336 if (
d->currentReadChannel <
d->readHeaders.size())
337 d->readHeaders[
d->currentReadChannel].clear();
349 if (
d->currentReadChannel <
d->readHeaders.size())
350 d->readHeaders[
d->currentReadChannel].clear();
360 d_func()->readHeaders.clear();
371 d->incomingDatagram.clear();
372 d->writeHeaders.clear();
390 qWarning(
"QSctpSocket::setMaximumChannelCount() is only allowed in UnconnectedState");
393#if defined(QSCTPSOCKET_DEBUG)
394 qDebug(
"QSctpSocket::setMaximumChannelCount(%i)",
count);
413 return d_func()->maximumChannelCount;
424 return d->maximumChannelCount != -1 &&
d->isBuffered;
444 qWarning(
"QSctpSocket::readDatagram(): operation is not permitted");
448 if (
d->currentReadChannel >=
d->readHeaders.size()
449 ||
d->readHeaders[
d->currentReadChannel].size() == 0) {
455 d->readHeaders[
d->currentReadChannel].front()));
456 d->readHeaders[
d->currentReadChannel].pop_front();
458#if defined (QSCTPSOCKET_DEBUG)
459 qDebug(
"QSctpSocket::readDatagram() returning datagram (%p, %i, \"%s\", %i)",
460 result.d->data.constData(),
462 result.senderAddress().toString().toLatin1().constData(),
481 qWarning(
"QSctpSocket::writeDatagram(): operation is not permitted");
485 if (datagram.d->data.isEmpty()) {
486 qWarning(
"QSctpSocket::writeDatagram() is called with empty datagram");
491#if defined QSCTPSOCKET_DEBUG
492 qDebug(
"QSctpSocket::writeDatagram(%p, %i, \"%s\", %i)",
493 datagram.d->data.constData(),
494 datagram.d->data.size(),
495 datagram.destinationAddress().toString().toLatin1().constData(),
496 datagram.destinationPort());
499 if (
d->writeHeaders.size() !=
d->writeBuffers.size())
500 d->writeHeaders.resize(
d->writeBuffers.size());
501 Q_ASSERT(
d->currentWriteChannel <
d->writeHeaders.size());
502 d->writeHeaders[
d->currentWriteChannel].push_back(datagram.d->header);
503 d->writeBuffer.setChunkSize(0);
504 d->writeBuffer.append(datagram.d->data);
506 d->socketEngine->setWriteNotificationEnabled(
true);
512#include "moc_qsctpsocket.cpp"
IOBluetoothL2CAPChannel * channel
QAbstractSocket::SocketError error() const
virtual void setWriteNotificationEnabled(bool enable)=0
virtual qint64 readDatagram(char *data, qint64 maxlen, QIpPacketHeader *header=nullptr, PacketHeaderOptions=WantNone)=0
virtual bool setOption(SocketOption option, int value)=0
virtual qint64 bytesAvailable() const =0
QString errorString() const
virtual qint64 writeDatagram(const char *data, qint64 len, const QIpPacketHeader &header)=0
void emitBytesWritten(qint64 bytes, int channel=0)
void emitReadyRead(int channel=0)
QAbstractSocketEngine * socketEngine
virtual bool canReadNotification()
virtual bool writeToSocket()
QAbstractSocket::SocketState state
void setErrorAndEmit(QAbstractSocket::SocketError errorCode, const QString &errorString)
virtual void disconnectFromHost()
Attempts to close the socket.
char * data()
\macro QT_NO_CAST_FROM_BYTEARRAY
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
static constexpr qsizetype max_size() noexcept
void clear()
Clears the contents of the byte array and makes it null.
void resize(qsizetype size)
Sets the size of the byte array to size bytes.
QVarLengthArray< QRingBuffer, 1 > writeBuffers
QVarLengthArray< QRingBuffer, 2 > readBuffers
bool isReadable() const
Returns true if data can be read from the device; otherwise returns false.
bool isWritable() const
Returns true if data can be written to the device; otherwise returns false.
virtual qint64 readLineData(char *data, qint64 maxlen)
Reads up to maxSize characters into data and returns the number of characters read.
virtual qint64 readData(char *data, qint64 maxlen)=0
Reads up to maxSize bytes from the device into data, and returns the number of bytes read or -1 if an...
virtual void close()
First emits aboutToClose(), then closes the device and sets its OpenMode to NotOpen.
qsizetype size() const noexcept
void push_back(parameter_type t)
void pop_front() noexcept
void resize(qsizetype size)
The QNetworkDatagram class provides the data and metadata of a UDP datagram.
bool canReadNotification() override
virtual ~QSctpSocketPrivate()
bool writeToSocket() override
void configureCreatedSocket() override
QByteArray incomingDatagram
QList< IpHeaderList > readHeaders
QList< IpHeaderList > writeHeaders
The QSctpSocket class provides an SCTP socket.
bool writeDatagram(const QNetworkDatagram &datagram)
Writes a datagram to the buffer of the current write channel.
qint64 readData(char *data, qint64 maxlen) override
\reimp
QSctpSocket(QObject *parent=nullptr)
Creates a QSctpSocket object in state UnconnectedState.
void close() override
\reimp
void setMaximumChannelCount(int count)
Sets the maximum number of channels that the application is prepared to support in datagram mode,...
void disconnectFromHost() override
\reimp
qint64 readLineData(char *data, qint64 maxlen) override
\reimp
bool isInDatagramMode() const
Returns true if the socket is running in datagram mode.
int maximumChannelCount() const
Returns the maximum number of channels that QSctpSocket is able to support.
virtual ~QSctpSocket()
Destroys the socket, closing the connection if necessary.
QNetworkDatagram readDatagram()
Reads a datagram from the buffer of the current read channel, and returns it as a QNetworkDatagram ob...
QByteArray toLatin1() const &
The QTcpSocket class provides a TCP socket.
constexpr size_type size() const noexcept
Combined button and popup list for selecting options.
static QString header(const QString &name)
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
constexpr const T & qMax(const T &a, const T &b)
GLenum GLenum GLsizei count
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLdouble GLdouble GLdouble GLdouble q