View Issue Details

IDProjectCategoryView StatusLast Update
0033241Open CASCADEOCCT:Foundation Classespublic2024-06-13 13:57
ReporteratereshiAssigned Todpasukhi  
PrioritynormalSeverityminor 
Status newResolutionopen 
PlatformWindowsOSVC++ 2017 
Target VersionUnscheduled 
Summary0033241: Foundation Classes - unrealized support for socket type of OSD_File leads to linking of an unused winsock library
DescriptionThe issure 0033235 was resolved by linking wsock32.lib
I found that the only reason to linking this lib is the call of "recv" function in OSD_File_getBuffer in OSD_File.cxx
But I can't find any traces of socket use such as WSA* functions and any Berkeley socket functions.
The only atemp to read OSD_File as socket is than parameter theIsSocket is true.
In turn, the parameter theIsSocket is true only if myIO member of OSD_File has FLAG_SOCKET flag.
The FLAG_SOCKET flag is generated only by _get_file_type function but it does it with mistake.
It uses return of windows api GetFileType function:
    const int aFileType = theFileHandle == INVALID_HANDLE_VALUE
                        ? FILE_TYPE_DISK
                        : GetFileType (theFileHandle);
    switch (aFileType)
    {
      case FILE_TYPE_UNKNOWN:
        return FLAG_SOCKET;
      case FILE_TYPE_DISK:
      {
        const TCollection_ExtendedString aFileNameW (theFileName, Standard_True);
        WIN32_FILE_ATTRIBUTE_DATA aFileInfo;
        if (GetFileAttributesExW (aFileNameW.ToWideString(), GetFileExInfoStandard, &aFileInfo))
        {
          return aFileInfo.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ? FLAG_DIRECTORY : FLAG_FILE;
        }
        return 0x80000000;
      }
      case FILE_TYPE_CHAR:
        return FLAG_DEVICE;
      case FILE_TYPE_PIPE:
        return FLAG_PIPE;
    }

But documentation of GetFileType says:
FILE_TYPE_PIPE - The specified file is a socket, a named pipe, or an anonymous pipe.
FILE_TYPE_UNKNOWN - Either the type of the specified file is unknown, or the function failed.

https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfiletype

So, I see three things:
1) OSD_File never create a socket by WSASocket or socket (to create a socket there should be WSAStartup call before)
2) OSD_File never can own a windows socket handle
3) FLAG_SOCKET and OSD_SOCKET macros are some kind of rudiment of old life.

... and I suggest three things:
1) To remove the unrealized support of sockets from code
2) To review the support of pipes
3) To remove the linking of wsock32.lib from all executables
TagsNo tags attached.
Test case number

Relationships

related to 0033235 verifieddpasukhi Configuration - Solving the problem with static building of ExpToCasExe 

Activities

There are no notes attached to this issue.

Issue History

Date Modified Username Field Change
2022-11-30 15:36 atereshi New Issue
2022-11-30 15:36 atereshi Assigned To => abv
2022-11-30 15:37 atereshi Description Updated
2022-11-30 15:40 atereshi Description Updated
2022-11-30 15:40 atereshi Relationship added related to 0033235
2022-12-01 11:14 atereshi Assigned To abv => msv
2023-03-06 19:38 ebelouso Target Version 7.7.1 => Unscheduled
2024-06-13 13:57 dpasukhi Assigned To msv => dpasukhi