599 memset(&storage, 0, storageSize); |
599 memset(&storage, 0, storageSize); |
600 |
600 |
601 // Peek 0 bytes into the next message. The size of the message may |
601 // Peek 0 bytes into the next message. The size of the message may |
602 // well be 0, so we can't check recvfrom's return value. |
602 // well be 0, so we can't check recvfrom's return value. |
603 ssize_t readBytes; |
603 ssize_t readBytes; |
|
604 #ifdef Q_OS_SYMBIAN |
|
605 char c; |
|
606 readBytes = ::recvfrom(socketDescriptor, &c, 1, MSG_PEEK, &storage.a, &storageSize); |
|
607 #else |
604 do { |
608 do { |
605 char c; |
609 char c; |
606 readBytes = ::recvfrom(socketDescriptor, &c, 1, MSG_PEEK, &storage.a, &storageSize); |
610 readBytes = ::recvfrom(socketDescriptor, &c, 1, MSG_PEEK, &storage.a, &storageSize); |
607 } while (readBytes == -1 && errno == EINTR); |
611 } while (readBytes == -1 && errno == EINTR); |
|
612 #endif |
608 |
613 |
609 // If there's no error, or if our buffer was too small, there must be a |
614 // If there's no error, or if our buffer was too small, there must be a |
610 // pending datagram. |
615 // pending datagram. |
611 bool result = (readBytes != -1) || errno == EMSGSIZE; |
616 bool result = (readBytes != -1) || errno == EMSGSIZE; |
612 |
617 |
659 memset(&aa, 0, sizeof(aa)); |
664 memset(&aa, 0, sizeof(aa)); |
660 QT_SOCKLEN_T sz; |
665 QT_SOCKLEN_T sz; |
661 sz = sizeof(aa); |
666 sz = sizeof(aa); |
662 |
667 |
663 ssize_t recvFromResult = 0; |
668 ssize_t recvFromResult = 0; |
|
669 #ifdef Q_OS_SYMBIAN |
|
670 char c; |
|
671 recvFromResult = ::recvfrom(socketDescriptor, maxSize ? data : &c, maxSize ? maxSize : 1, |
|
672 0, &aa.a, &sz); |
|
673 #else |
664 do { |
674 do { |
665 char c; |
675 char c; |
666 recvFromResult = ::recvfrom(socketDescriptor, maxSize ? data : &c, maxSize ? maxSize : 1, |
676 recvFromResult = ::recvfrom(socketDescriptor, maxSize ? data : &c, maxSize ? maxSize : 1, |
667 0, &aa.a, &sz); |
677 0, &aa.a, &sz); |
668 } while (recvFromResult == -1 && errno == EINTR); |
678 } while (recvFromResult == -1 && errno == EINTR); |
|
679 #endif |
669 |
680 |
670 if (recvFromResult == -1) { |
681 if (recvFromResult == -1) { |
671 setError(QAbstractSocket::NetworkError, ReceiveDatagramErrorString); |
682 setError(QAbstractSocket::NetworkError, ReceiveDatagramErrorString); |
672 } else if (port || address) { |
683 } else if (port || address) { |
673 qt_socket_getPortAndAddress(&aa, port, address); |
684 qt_socket_getPortAndAddress(&aa, port, address); |
830 Q_Q(QNativeSocketEngine); |
841 Q_Q(QNativeSocketEngine); |
831 |
842 |
832 // ignore the SIGPIPE signal |
843 // ignore the SIGPIPE signal |
833 qt_ignore_sigpipe(); |
844 qt_ignore_sigpipe(); |
834 |
845 |
|
846 ssize_t writtenBytes; |
|
847 #ifdef Q_OS_SYMBIAN |
|
848 // Symbian does not support signals natively and Open C returns EINTR when moving to offline |
|
849 writtenBytes = ::write(socketDescriptor, data, len); |
|
850 #else |
835 // loop while ::write() returns -1 and errno == EINTR, in case |
851 // loop while ::write() returns -1 and errno == EINTR, in case |
836 // of an interrupting signal. |
852 // of an interrupting signal. |
837 ssize_t writtenBytes; |
|
838 do { |
853 do { |
839 #ifdef Q_OS_SYMBIAN |
|
840 writtenBytes = ::write(socketDescriptor, data, len); |
|
841 #else |
|
842 writtenBytes = qt_safe_write(socketDescriptor, data, len); |
854 writtenBytes = qt_safe_write(socketDescriptor, data, len); |
843 #endif |
|
844 // writtenBytes = QT_WRITE(socketDescriptor, data, len); ### TODO S60: Should this line be removed or the one above it? |
|
845 } while (writtenBytes < 0 && errno == EINTR); |
855 } while (writtenBytes < 0 && errno == EINTR); |
|
856 #endif |
846 |
857 |
847 if (writtenBytes < 0) { |
858 if (writtenBytes < 0) { |
848 switch (errno) { |
859 switch (errno) { |
849 case EPIPE: |
860 case EPIPE: |
850 case ECONNRESET: |
861 case ECONNRESET: |
880 qWarning("QNativeSocketEngine::unbufferedRead: Invalid socket"); |
891 qWarning("QNativeSocketEngine::unbufferedRead: Invalid socket"); |
881 return -1; |
892 return -1; |
882 } |
893 } |
883 |
894 |
884 ssize_t r = 0; |
895 ssize_t r = 0; |
|
896 #ifdef Q_OS_SYMBIAN |
|
897 r = ::read(socketDescriptor, data, maxSize); |
|
898 #else |
885 do { |
899 do { |
886 #ifdef Q_OS_SYMBIAN |
|
887 r = ::read(socketDescriptor, data, maxSize); |
|
888 #else |
|
889 r = qt_safe_read(socketDescriptor, data, maxSize); |
900 r = qt_safe_read(socketDescriptor, data, maxSize); |
890 #endif |
|
891 } while (r == -1 && errno == EINTR); |
901 } while (r == -1 && errno == EINTR); |
|
902 #endif |
892 |
903 |
893 if (r < 0) { |
904 if (r < 0) { |
894 r = -1; |
905 r = -1; |
895 switch (errno) { |
906 switch (errno) { |
896 #if EWOULDBLOCK-0 && EWOULDBLOCK != EAGAIN |
907 #if EWOULDBLOCK-0 && EWOULDBLOCK != EAGAIN |