86#include "private/qbytearray_p.h"
88#ifdef QSCTPSOCKET_DEBUG
97 : maximumChannelCount(0)
112#if defined (QSCTPSOCKET_DEBUG)
113 qDebug(
"QSctpSocketPrivate::canReadNotification()");
117 if (!
q->isInDatagramMode())
121 bool currentChannelRead =
false;
129 if (bytesToRead == 0) {
139#if defined (QSCTPSOCKET_DEBUG)
140 qDebug(
"QSctpSocketPrivate::canReadNotification() about to read %lli bytes",
146 if (readBytes <= 0) {
147 if (readBytes == -2) {
149 return currentChannelRead;
153 if (readBytes == 0) {
155 QSctpSocket::tr(
"The remote host closed the connection"));
157#if defined (QSCTPSOCKET_DEBUG)
158 qDebug(
"QSctpSocketPrivate::canReadNotification() read failed: %s",
164#if defined (QSCTPSOCKET_DEBUG)
165 qDebug(
"QSctpSocketPrivate::canReadNotification() disconnecting socket");
167 q->disconnectFromHost();
168 return currentChannelRead;
170 datagramSize += int(readBytes);
171 }
while (!
header.endOfRecord);
173#if defined (QSCTPSOCKET_DEBUG)
174 qDebug(
"QSctpSocketPrivate::canReadNotification() got datagram from channel %i, size = %i",
175 header.streamNumber, datagramSize);
179 if (!
q->isReadable()) {
196 if (
header.streamNumber == savedCurrentChannel)
197 currentChannelRead =
true;
202 return currentChannelRead;
210#if defined (QSCTPSOCKET_DEBUG)
211 qDebug(
"QSctpSocketPrivate::writeToSocket()");
215 if (!
q->isInDatagramMode())
223 bool currentChannelWritten =
false;
226 transmitting =
false;
243 return currentChannelWritten;
246#if defined (QSCTPSOCKET_DEBUG)
247 qDebug(
"QSctpSocketPrivate::writeToSocket() write error, aborting. %s",
252 q->disconnectFromHost();
253 return currentChannelWritten;
256#if defined (QSCTPSOCKET_DEBUG)
257 qDebug(
"QSctpSocketPrivate::writeToSocket() sent datagram of size %lli to channel %i",
263 channelBuffer.
read();
268 if (
channel == savedCurrentChannel)
269 currentChannelWritten =
true;
274#if defined (QSCTPSOCKET_DEBUG)
275 qDebug(
"QSctpSocketPrivate::writeToSocket() socket is closing - returning");
277 return currentChannelWritten;
280 }
while (transmitting);
285 q->disconnectFromHost();
289 return currentChannelWritten;
312#if defined(QSCTPSOCKET_DEBUG)
313 qDebug(
"QSctpSocket::QSctpSocket()");
315 d_func()->isBuffered =
true;
325#if defined(QSCTPSOCKET_DEBUG)
326 qDebug(
"QSctpSocket::~QSctpSocket()");
337 if (
d->currentReadChannel <
d->readHeaders.size())
338 d->readHeaders[
d->currentReadChannel].clear();
350 if (
d->currentReadChannel <
d->readHeaders.size())
351 d->readHeaders[
d->currentReadChannel].clear();
361 d_func()->readHeaders.clear();
372 d->incomingDatagram.clear();
373 d->writeHeaders.clear();
391 qWarning(
"QSctpSocket::setMaximumChannelCount() is only allowed in UnconnectedState");
394#if defined(QSCTPSOCKET_DEBUG)
395 qDebug(
"QSctpSocket::setMaximumChannelCount(%i)",
count);
414 return d_func()->maximumChannelCount;
425 return d->maximumChannelCount != -1 &&
d->isBuffered;
445 qWarning(
"QSctpSocket::readDatagram(): operation is not permitted");
449 if (
d->currentReadChannel >=
d->readHeaders.size()
450 ||
d->readHeaders[
d->currentReadChannel].size() == 0) {
456 d->readHeaders[
d->currentReadChannel].front()));
457 d->readHeaders[
d->currentReadChannel].pop_front();
459#if defined (QSCTPSOCKET_DEBUG)
460 qDebug(
"QSctpSocket::readDatagram() returning datagram (%p, %i, \"%s\", %i)",
461 result.d->data.constData(),
463 result.senderAddress().toString().toLatin1().constData(),
482 qWarning(
"QSctpSocket::writeDatagram(): operation is not permitted");
487 qWarning(
"QSctpSocket::writeDatagram() is called with empty datagram");
492#if defined QSCTPSOCKET_DEBUG
493 qDebug(
"QSctpSocket::writeDatagram(%p, %i, \"%s\", %i)",
500 if (
d->writeHeaders.size() !=
d->writeBuffers.size())
501 d->writeHeaders.resize(
d->writeBuffers.size());
502 Q_ASSERT(
d->currentWriteChannel <
d->writeHeaders.size());
503 d->writeHeaders[
d->currentWriteChannel].push_back(datagram.d->
header);
504 d->writeBuffer.setChunkSize(0);
505 d->writeBuffer.append(datagram.d->
data);
507 d->socketEngine->setWriteNotificationEnabled(
true);
513#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.
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
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.
QString toString() const
Returns the address as a string.
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.
QHostAddress destinationAddress() const
Returns the destination address associated with this datagram.
int destinationPort() const
Returns the port number of the destination associated with this datagram.
const char * readPointer() const
qint64 nextDataBlockSize() const
Q_CORE_EXPORT qint64 read(char *data, qint64 maxLength)
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.
QT_BEGIN_NAMESPACE constexpr qsizetype MaxByteArraySize
static QString header(const QString &name)
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
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent