Yes, you said interesting things, but I really want to construct my API like the QTcpSocket and QUdpSocket (and other sockets), That's why I did it like this. I don't want to limit my users. For a personnal project, I will do like you say, but here I think I can't do that :/
Anyway, I did some functions that works:
qint64 QWsSocket::bytesAvailable() const
{
return buffer.size();
}
qint64 QWsSocket::readData( char * data, qint64 maxSize )
{
int dataSize=buffer.size();
int i=0;
while( i<maxSize && i<dataSize )
{
data[i] = buffer.dequeue().toAscii();
i++;
}
return i;
}
qint64 QWsSocket::writeData( const char * data, qint64 maxSize )
{
return tcpSocket->write(data, maxSize);
}
{
qint64 sz = bytesAvailable();
char * data = new char[sz];
sz = readData(data, sz);
}
bool QWsSocket::getChar(char * c)
{
*c = 0;
if ( bytesAvailable() == 0 )
return false;
readData(c, 1);
return true;
}
qint64 QWsSocket::read(char * data, qint64 maxSize)
{
return readData(data, maxSize);
}
qint64 QWsSocket::bytesAvailable() const
{
return buffer.size();
}
qint64 QWsSocket::readData( char * data, qint64 maxSize )
{
int dataSize=buffer.size();
int i=0;
while( i<maxSize && i<dataSize )
{
data[i] = buffer.dequeue().toAscii();
i++;
}
return i;
}
qint64 QWsSocket::writeData( const char * data, qint64 maxSize )
{
return tcpSocket->write(data, maxSize);
}
QByteArray QWsSocket::readAll()
{
qint64 sz = bytesAvailable();
char * data = new char[sz];
sz = readData(data, sz);
return QByteArray(data, sz);
}
bool QWsSocket::getChar(char * c)
{
*c = 0;
if ( bytesAvailable() == 0 )
return false;
readData(c, 1);
return true;
}
qint64 QWsSocket::read(char * data, qint64 maxSize)
{
return readData(data, maxSize);
}
To copy to clipboard, switch view to plain text mode
Bookmarks