Esempio n. 1
0
// Processes incoming read events. They can come from the server or
// from the GPS device.
void GpsClient::processEvent( fd_set *fdMask )
{
    if( ipcPort )
    {
        int sfd = clientData.getSock();

        if( sfd != -1 && FD_ISSET( sfd, fdMask ) )
        {
            int loops = 0;

            // Try to process several messages from the client in order. That
            // is more effective as to wait for a new select call.
            while( loops++ < 32 )
            {
                readServerMsg();

                if( shutdown == true )
                {
                    break;
                }

                // Check, if more bytes are available in the receiver buffer because we
                // use blocking IO.
                int bytes = 0;

                // Number of bytes currently in the socket receiver buffer.
                if( ioctl( sfd, FIONREAD, &bytes) == -1 )
                {
                    qWarning() << "GpsClient::processEvent():"
                               << "ioctl() returns with Errno="
                               << errno
                               << "," << strerror(errno);
                    break;
                }

                if( bytes <= 0 )
                {
                    break;
                }
            }
        }
    }

    if( fd != -1 && FD_ISSET( fd, fdMask ) )
    {
        if( readGpsData() == false )
        {
            // problem occurred, likely buffer overrun. we do restart the GPS
            // receiving.
            int error = errno; // Save errno
            closeGps();

            if( error == ECONNREFUSED )
            {
                // BT devices can reject a connection try. If we don't return here
                // we run in an endless loop.
                setShutdownFlag(true);
            }
            else
            {
                sleep(3);
                // reopen connection
                openGps( device.data(), ioSpeedDevice );
            }
        }
    }
}
TcpClient::TcpClient(QObject * parent)
    : QObject(parent)
{
    QObject::connect(&m_Socket, SIGNAL(connected()), this, SLOT(connectionSuccess()));
    QObject::connect(&m_Socket, SIGNAL(readyRead()), this, SLOT(readServerMsg()));
}