Socket applications should pay attention to in WINDOWS transplantation from UNIX, Sun Chengshan Sockets, Science and Technology, Zibo City, Shandong Province, today has become the most popular network communication application interface. Sockets were initially divided by Berkeley, Calif, Berkeley, developed to UNIX operating systems, which was transplanted to DOS and Windows systems, especially in recent years, have been widely popular in the world, and has grown rapidly. It has further laid its dominance in the field of network communication program development. Cross-system network interconnection is getting higher and higher in my country. Recently, in the development of banks and securities networking systems, we tried to do transplants from UNIX Sockets to Windows Sockets communication applications, seeing to work with the problems that should be paid attention to in the transplantation process. The people will work together to discuss, in order to play the role of tile jade.
Modify the definition of the header file in the UNIX Sockets application contains the statement of the header file as #include
Although the collection of sockets is still represented by fd_set, the code directly modified the FD_SET structure in the UNIX Sockets source file will not work properly in the Windows Sockets environment. Therefore, the direct modification of the structure fd_set should be changed to the source program to be modified by using the fd_xxx macro when performing migration. You should try to use the WSA Macro in the Windows Sockets program to define a macro starting in the Windows Sockets header file, using these macros in the program, can greatly increase the readability of the program. For example: errno = wsagetlasterror (); if (errno = wsaewoldblock) {...} These macros are Windows Sockets may have errors in the application implementation process, which can be expanded to make the program's read and write, it is The Windows Sockets application writes the specification that follows the staff developer, so these macros should be used as much as possible to increase the readability of the program. The processing of blocking calls Windows is a non-preemptive multi-task environment. The switching between the tasks is driven by message. If an application cannot actively give it to control, other applications cannot be executed, this is to have a UNIX operating system The difference in essence. The blocking problem must be considered for applications that are transplanted from the UNIX Sockets environment. To solve the problem of blocking, Windows Sockets specials an increase in blocking processing function: wsaisblocking () detection blocking call WSACANCELBLOCKINGCALL () Cancel a ongoing blocking call wsasetBlocking () Setting your own blocking Handling routine WSAUNHOOKBLOCKINGHOOK () Restore The default blocking process routine is not affecting the blocking process routine in the original environment, when installing your own blocking process routine, pay attention to the program instant pointer to the returned previously installed blocking process routine, and after the processing restore. Try to change the blocking call to the message-based asynchronous operation in the Windows Sockets network program design, although it allows blocking operations, a blocking may block the entire Windows environment, and in the UNIX Sockets program, the default mode of operation of the socket is Blocking. Windows Sockets adopts messy asynchronous access policies in order to support Windows messaging mechanisms, which uses messages based asynchronous access policies. To this end, it is recommended to change the blocking call in the source program to the message-based asynchronous operation. Windows Sockets has added the following functions to implement asynchronous access operations: Wsaasyncselect () standard Berkeley function select () asynchronous version
WSaasyncGetxby () Standard Berkeley Function getXByy ()
WSACANCELASYNCREQUEST () Cancel Function WSAAsyncGetxByy () Execution
Transplantation of the UNIX Sockets application is a more cumbersome work, in addition to the direct related to Sockets in the transplant, pay attention to the difference in the development environment, and the program should also be For some corresponding adjustments, for example, some pointers related to the Windows application should be set to the FAR type, etc., this is no longer described here.