src/network/socket/qlocalsocket_win.cpp
changeset 7 f7bc934e204c
parent 3 41300fa6a67c
child 22 79de32ba3296
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
     1 /****************************************************************************
     1 /****************************************************************************
     2 **
     2 **
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     4 ** All rights reserved.
     4 ** All rights reserved.
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
     6 **
     6 **
     7 ** This file is part of the QtNetwork module of the Qt Toolkit.
     7 ** This file is part of the QtNetwork module of the Qt Toolkit.
     8 **
     8 **
   106        readSequenceStarted(false),
   106        readSequenceStarted(false),
   107        pendingReadyRead(false),
   107        pendingReadyRead(false),
   108        pipeClosed(false),
   108        pipeClosed(false),
   109        state(QLocalSocket::UnconnectedState)
   109        state(QLocalSocket::UnconnectedState)
   110 {
   110 {
       
   111 }
       
   112 
       
   113 QLocalSocketPrivate::~QLocalSocketPrivate()
       
   114 {
       
   115     destroyPipeHandles();
       
   116     CloseHandle(overlapped.hEvent);
       
   117 }
       
   118 
       
   119 void QLocalSocketPrivate::destroyPipeHandles()
       
   120 {
       
   121     if (handle != INVALID_HANDLE_VALUE) {
       
   122         DisconnectNamedPipe(handle);
       
   123         CloseHandle(handle);
       
   124     }
   111 }
   125 }
   112 
   126 
   113 void QLocalSocket::connectToServer(const QString &name, OpenMode openMode)
   127 void QLocalSocket::connectToServer(const QString &name, OpenMode openMode)
   114 {
   128 {
   115     Q_D(QLocalSocket);
   129     Q_D(QLocalSocket);
   386         return;
   400         return;
   387     }
   401     }
   388     d->readSequenceStarted = false;
   402     d->readSequenceStarted = false;
   389     d->pendingReadyRead = false;
   403     d->pendingReadyRead = false;
   390     d->pipeClosed = false;
   404     d->pipeClosed = false;
   391     DisconnectNamedPipe(d->handle);
   405     d->destroyPipeHandles();
   392     CloseHandle(d->handle);
       
   393     d->handle = INVALID_HANDLE_VALUE;
   406     d->handle = INVALID_HANDLE_VALUE;
   394     ResetEvent(d->overlapped.hEvent);
   407     ResetEvent(d->overlapped.hEvent);
   395     d->state = UnconnectedState;
   408     d->state = UnconnectedState;
   396     emit stateChanged(d->state);
   409     emit stateChanged(d->state);
   397     emit disconnected();
   410     emit disconnected();
   522 }
   535 }
   523 
   536 
   524 bool QLocalSocket::isValid() const
   537 bool QLocalSocket::isValid() const
   525 {
   538 {
   526     Q_D(const QLocalSocket);
   539     Q_D(const QLocalSocket);
   527     return (d->handle != INVALID_HANDLE_VALUE);
   540     if (d->handle == INVALID_HANDLE_VALUE)
       
   541         return false;
       
   542 
       
   543     return PeekNamedPipe(d->handle, NULL, 0, NULL, NULL, NULL);
   528 }
   544 }
   529 
   545 
   530 bool QLocalSocket::waitForReadyRead(int msecs)
   546 bool QLocalSocket::waitForReadyRead(int msecs)
   531 {
   547 {
   532     Q_D(QLocalSocket);
   548     Q_D(QLocalSocket);