kextsock.h
来自「konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版」· C头文件 代码 · 共 1,111 行 · 第 1/3 页
H
1,111 行
* will return -1 and the system error will be set to EWOULDBLOCK. * * If we are buffering, this function will simply transfer the data into the * write buffer. This function will then always succeed, as long as there is * enough room in the buffer. If the buffer size was limited and that limit * is reached, this function will copy no more bytes than that limit. Trying * to write with a full buffer will return -1 and set system error to * EWOULDBLOCK. * * @param data the data to write * @param len the length of data to write * @return the number of bytes written from @p data buffer. * The return value might be less than @p len if the output buffers cannot * accommodate that many bytes and -1 in the case of an errro. */ virtual Q_LONG writeBlock(const char *data, Q_ULONG len); /** * Peeks at a block of data from the socket. * * This is exactly like read, except that the data won't be flushed from the * read buffer. * * If this socket is not buffered, this function will always return with * 0 bytes copied. * * @param data where to store the data * @param maxlen how many bytes to copy, at most * @return the number of bytes copied. 0 does not mean end-of-file * condition. */ virtual int peekBlock(char *data, uint maxlen); /** * Reimplementation of unreadBlock() method. This is so because unreading in * sockets doesn't make sense, so this function will always return -1 (error) * and set the system error to ENOSYS. * @return always -1 (error) */ virtual int unreadBlock(const char *data, uint len); /** * Returns the number of available bytes yet to be read via readBlock * and family of functions. * * Note: as of now, this only works on input-buffered sockets. This will * change in the future * @return The number of available bytes, or -1 on error or -2 if this call is invalid * in the current state. */ virtual int bytesAvailable() const; /** * Waits @p msec milliseconds for more data to be available (use 0 to * wait forever). The return value is the amount of data available for * read in the read buffer. * * @param msec milliseconds to wait * @return -1 in case of system error and -2 in case of invalid socket * state */ virtual int waitForMore(int msec); /** * Gets a single character (unsigned char) from the stream. * @return the value of the character. Negative if there was an error. */ virtual int getch(); /** * Writes a single character (unsigned char) to the stream. All other bits * will be ignored. * @param ch character to write, converted to char */ virtual int putch(int ch); /** * Unreads one character from the stream. This is not possible on sockets. * @return always returns -1 on sockets. */ virtual int ungetch(int) { return -1; } /** * Toggles the emission of the readyRead signal. * * Note that this signal is emitted every time more data is available to be * read, so you might get flooded with it being emitted every time, when in * non-buffered mode. However, in buffered mode, this signal will be * emitted only when there is data coming in from the wire. * By default, this flag is set to false, i.e., signal not being emitted. * @param enable if true, the signal will be emitted */ virtual void enableRead(bool enable); /** * Toggles the emission of the readyWrite signal. * * Note that this signal is emitted only when the OS is ready to receive more * data, which means that the write buffer is empty. And when that is reached, * this signal will possibly be emitted on every loop, so you might * want to disable it. By default, this flag is set to false. * @param enable if true, the signal will be emitted */ virtual void enableWrite(bool enable);signals: /** * This signal is emitted whenever an asynchronous lookup process is done. * The parameter @p count tells * @param count the number of results */ void lookupFinished(int count); /** * This signal is emitted whenever we connected asynchronously to a host. */ void connectionSuccess(); /** * This signal is emitted whenever our asynchronous connection attempt * failed to all hosts listed. * @param error the errno code of the last connection attempt */ void connectionFailed(int error); /** * This signal is emitted whenever this socket is ready to accept another * socket. * @see accept() */ void readyAccept();protected: int sockfd; // file descriptor of the socketprotected slots: void socketActivityRead(); void socketActivityWrite(); void dnsResultsReady(); void startAsyncConnectSlot(); void connectionEvent();protected: QSocketNotifier *readNotifier(); QSocketNotifier *writeNotifier();private: // protection against accidental use KExtendedSocket(KExtendedSocket&); KExtendedSocket& operator=(KExtendedSocket&); /** * This is actually a wrapper around getaddrinfo(). * @internal */ static int doLookup(const QString& host, const QString& serv, addrinfo& hint, kde_addrinfo** result);protected: /** * Sets the error code */ void setError(int errorkind, int error); inline void cleanError() { setError(IO_Ok, 0); } /** * Sets the socket status. For derived classes only. */ void setSocketStatus(int status);public: /** * Performs resolution on the given socket address. * * That is, tries to resolve the raw form of the socket address into a textual * representation. * * @param sock the socket address * @param len the length of the socket address * @param host where the hostname will be written * @param port where the service-port will be written * @param flags the same flags as getnameinfo() * @returns 0 on success, nonzero otherwise. */ static int resolve(sockaddr* sock, ksocklen_t len, QString& host, QString& port, int flags = 0) KDE_DEPRECATED; /** * Performs resolution on the given socket address. * * That is, tries to resolve the raw form of the socket address into a textual * representation. * * @param sock the socket address * @param host where the hostname will be written * @param port where the service-port will be written * @param flags the same flags as getnameinfo() * @returns 0 on success, nonzero otherwise. */ static int resolve(::KSocketAddress* sock, QString& host, QString& port, int flags = 0) KDE_DEPRECATED; /** @deprecated * This function is now deprecated. Please use @ref KNetwork::KResolver::resolve. * * Performs lookup on the given hostname/port combination and returns a list * of matching addresses. * The error code can be transformed into string by KExtendedSocket::strError() * with code of IO_LookupError. * * IMPORTANT: the result values of the QPtrList must be deleted after use. So, * if you don't copy the KAddressInfo objects, the best way to assure that * is to call setAutoDelete(true) on the list right after this function * returns. If you do copy the results out, you must assure that the objects * get deleted when they are not needed any more. * * @param host the hostname to look up * @param port the port/service to look up * @param flags flags to be used when looking up, Flags * @param error pointer to a variable holding the error code * @return a list of KAddressInfos */ static QPtrList<KAddressInfo> lookup(const QString& host, const QString& port, int flags = 0, int *error = 0) KDE_DEPRECATED; /** * Returns the local socket address * Remember to delete the returned object when it is no longer needed. * @param fd the file descriptor * @return the local socket address or 0 if an error occurred. Delete after use. */ static ::KSocketAddress *localAddress(int fd) KDE_DEPRECATED; /** * Returns the peer socket address. Use KExtendedSocket::resolve() to * resolve this to a human-readable hostname/service or port. * Remember to delete the returned object when it is no longer needed. * @param fd the file descriptor * @return the peer socket address or 0 if an error occurred. Delete after use. */ static ::KSocketAddress *peerAddress(int fd) KDE_DEPRECATED; /** * Returns the representing text of this error code * @param code the error code, as seen in status() * @param syserr the system error, as from systemError() * @return the text for the given error code */ static QString strError(int code, int syserr); /** * Sets/unsets address reusing flag for this socket. * * This function returns true if the value was set correctly. That is NOT * the result of the set. * @param fd the file descriptor * @param enable if true, set address reusable * @return true on success, false on failure. */ static bool setAddressReusable(int fd, bool enable) KDE_DEPRECATED;protected: virtual void virtual_hook( int id, void* data );private: KExtendedSocketPrivate *d; friend class KSocket; friend class KServerSocket;};/** @deprecated * This class is now deprecated. Please see @ref KNetwork::KResolver for the new API. * * Contains information about an internet address. It wraps addrinfo, * see getaddrinfo(3) for more information. */class KDECORE_EXPORT KAddressInfo{private: addrinfo *ai; ::KSocketAddress *addr; inline KAddressInfo() : ai(0), addr(0) { } // KAddressInfo(addrinfo *ai); KAddressInfo(KAddressInfo&) { } KAddressInfo& operator=(KAddressInfo&) { return *this; }public: ~KAddressInfo(); /** * Returns the KAddressInfo's KSocketAddress. * Only valid as long as the KAddressInfo exists. */ inline KDE_DEPRECATED operator const ::KSocketAddress*() const { return addr; } /** * Returns the KAddressInfo's addrinfo. */ inline KDE_DEPRECATED operator const addrinfo&() const { return *ai; } /** * Returns a pointer to KAddressInfo's addrinfo. * Only valid as long as the KAddressInfo exists. */ inline KDE_DEPRECATED operator const addrinfo*() const { return ai; } /** * Returns the KAddressInfo's KSocketAddress. * Only valid as long as the KAddressInfo exists. * @return the KAddressInfo's KSocketAddress. */ inline KDE_DEPRECATED const ::KSocketAddress* address() const { return addr; } /** * Returns the flags of the address info (see getaddrinfo(3)). * @return the flags of the addres info. */ int flags() const KDE_DEPRECATED; /** * Returns the family of the address info (see getaddrinfo(3)). * @return the family of the addres info. */ int family() const KDE_DEPRECATED; /** * Returns the socket type of the address info (see getaddrinfo(3)). * @return the socket type of the addres info. */ int socktype() const KDE_DEPRECATED; /** * Returns the protocol of the address info (see getaddrinfo(3)). * @return the protocol of the addres info. */ int protocol() const KDE_DEPRECATED; /** * Returns the official name of the host (see getaddrinfo(3)). * Only valid as long as the KAddressInfo exists. * @return the official name of the host */ const char* canonname() const KDE_DEPRECATED; /** * Returns the length of the KSocketAddress. * @return the KSocketAddress's length */ inline int length() const { if (addr) return addr->size(); return 0; } friend class KExtendedSocket;};#endif //Q_OS_UNIX#endif // KEXTSOCK_H
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?