tailieunhanh - Networking and Network Programming 2 TCP/IP phần 3

trả về lỗi WinSock cuối cùng đã xảy ra. Trong MS-DOS hoặc thế giới lập trình UNIX, có lẽ bạn đang sử dụng để kiểm tra biến theerrno, mà là một ứng dụng cụ thể biến toàn cầu có sẵn trong tất cả các chương trình. Vì WinSock là không thực sự là một phần của hệ điều hành nhưng thay vì sau đó tiện ích này, errno không thể được sử dụng. | Part II Basics of WinSock Programming WSAGetLastError The WSAGetLastError function doesn t deal exclusively with startup or shutdown procedures but it needs to be addressed early. Its function prototype looks like int PASCAL FAR WSAGetLastError void WSAGetLastError returns the last WinSock error that occurred. In the MS-DOS or UNIX programming worlds you re probably used to examining the errno variable which is an application-specific global variable available in all programs. Because WinSock isn t really part of the operating system but is instead a later add-on errno couldn t be used. As soon as a WinSock API call fails you should call WSAGetLastError to retrieve specific details of the error. As an example if WSAStartup is called with a wVersionRequested which is earlier than any WinSock API supported by the WinSock DLL WSAStartup returns an error indicator. Calling WSAGetLastError immediately after the failed call to WSAStartup reveals the WSAVERNTSUPPORTED error. The other possible error values generated by WSAStartup are WSASYSNOTREADY if the network subsystem is failing and WSAEINVAL if an invalid argument is passed. Possible error values for WSACleanup include WSANOTINITIALIZED if WSAStartup wasn t called successfully WSAENETDOWN if the network subsystem is failing and WSAEINPROGRESS if a blocking WinSock operation is currently in progress. Summary This chapter discussed Just the beginning of writing a WinSock application. Chapter 8 Sample Applications presents a program that uses the WSADATA structure in the call to WSAStartup to present some useful information to the application user. The next few chapters will continue to present the mandatory WinSock functions useful to most applications. 6 Conversion and Database Functions - Part II Basics of WinSock Programming WinSock provides a set of procedures commonly referred to as the database functions. The duty of these database functions is to convert the host and service names that are used by humans into a

TỪ KHÓA LIÊN QUAN