From: Rolf K. <lab...@us...> - 2004-04-09 23:09:29
|
Update of /cvsroot/opengtoolkit/pipe/c_source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5276/c_source Modified Files: pipes.c pipes.dsp Added Files: pipes.rc Log Message: Made the named pipe operations work and added a very simplistic test VI, which does not yet conform to OpenG test standards --- NEW FILE: pipes.rc --- #include <windows.h> #define IDR_VERSION1 1 IDR_VERSION1 VERSIONINFO MOVEABLE IMPURE LOADONCALL DISCARDABLE FILEVERSION 0,9,0,0 PRODUCTVERSION 0,9,0,0 FILEFLAGSMASK VS_FFI_FILEFLAGSMASK FILEFLAGS 0 FILEOS VOS_DOS_WINDOWS32 FILETYPE VFT_DLL FILESUBTYPE 0 // not used BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "040904E4" //language ID = U.S. English, char set = Windows, Multilingual BEGIN VALUE "FileDescription", "OpenG Windows Pipe support library\0" VALUE "FileVersion", "0.9.0.0\0" VALUE "InternalName", "ogpipes\0" VALUE "OriginalFilename", "ogpipes.dll\0" VALUE "ProductName", "ogpipes.dll\0" VALUE "Comments","LabVIEW support library to implement pipe operations on Windows\0" VALUE "LegalCopyright", "(C) 2004 Rolf Kalbermatter\0" END END BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x0409, 1252 END END Index: pipes.dsp =================================================================== RCS file: /cvsroot/opengtoolkit/pipe/c_source/pipes.dsp,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** pipes.dsp 11 Mar 2004 23:44:05 -0000 1.2 --- pipes.dsp 9 Apr 2004 22:56:05 -0000 1.3 *************** *** 104,107 **** --- 104,111 ---- # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" + # Begin Source File + + SOURCE=.\pipes.rc + # End Source File # End Group # End Target Index: pipes.c =================================================================== RCS file: /cvsroot/opengtoolkit/pipe/c_source/pipes.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** pipes.c 1 Apr 2004 09:48:40 -0000 1.6 --- pipes.c 9 Apr 2004 22:55:51 -0000 1.7 *************** *** 70,91 **** return mgArgErr; ! if (WaitNamedPipe(name, 2000)) { switch (mode) { case kReadMode: ! dwMode = FILE_READ_DATA; break; case kWriteMode: ! dwMode = FILE_WRITE_DATA; break; case kReadWriteMode: ! dwMode = FILE_READ_DATA | FILE_WRITE_DATA; break; } /* There is a server to connect to, so connect as client */ ! handle = CreateFile(name, dwMode, 0, NULL, OPEN_EXISTING, ! 0 /* SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION */, NULL); } else --- 70,90 ---- return mgArgErr; ! if (WaitNamedPipe(name, 1000)) { switch (mode) { case kReadMode: ! dwMode = GENERIC_READ; break; case kWriteMode: ! dwMode = GENERIC_WRITE; break; case kReadWriteMode: ! dwMode = GENERIC_READ | GENERIC_WRITE; break; } /* There is a server to connect to, so connect as client */ ! handle = CreateFile(name, dwMode, 0, NULL, OPEN_EXISTING, 0 , NULL); } else *************** *** 105,109 **** /* There is no server to connect to, so create our own server */ ! handle = CreateNamedPipe(name, dwMode, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, PIPE_UNLIMITED_INSTANCES, 1024, 1024, NMPWAIT_USE_DEFAULT_WAIT, NULL); } --- 104,108 ---- /* There is no server to connect to, so create our own server */ ! handle = CreateNamedPipe(name, dwMode, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_NOWAIT, PIPE_UNLIMITED_INSTANCES, 1024, 1024, NMPWAIT_USE_DEFAULT_WAIT, NULL); } *************** *** 307,311 **** { MgErr err = noErr; ! uInt32 bytes = *bytesRead; #if defined(MSWin) DWORD ret; --- 306,310 ---- { MgErr err = noErr; ! uInt32 bytesReq = *bytesRead; #if defined(MSWin) DWORD ret; *************** *** 319,323 **** *eof = FALSE; ! err = NumericArrayResize(uB, 1, (UHandle*)&data, bytes); if (err) return err; --- 318,322 ---- *eof = FALSE; ! err = NumericArrayResize(uB, 1, (UHandle*)&data, bytesReq); if (err) return err; *************** *** 327,343 **** characters as it sees to be in the array into the new handle if any. */ ! LStrLen(*data) = bytes; #if defined(MSWin) ! if (!ReadFile((HANDLE)fd, LStrBuf(*data), bytes, bytesRead, NULL)) { ret = GetLastError(); ! *eof = (ret == ERROR_HANDLE_EOF); if (!*eof) err = Win32ToLVErr(ret); } #elif defined(Unix) ! ret = read((pipe_t)fd, LStrBuf(*data), bytes) if (ret < 0) { --- 326,361 ---- characters as it sees to be in the array into the new handle if any. */ ! LStrLen(*data) = bytesReq; #if defined(MSWin) ! if (!PeekNamedPipe((HANDLE)fd, NULL, 0, NULL, bytesRead, NULL)) { ret = GetLastError(); ! *eof = (ret == ERROR_HANDLE_EOF || ret == ERROR_BROKEN_PIPE); if (!*eof) err = Win32ToLVErr(ret); + *bytesRead = 0; + } + if (bytesReq < *bytesRead) + *bytesRead = bytesReq; + + if (*bytesRead) + { + if (!ReadFile((HANDLE)fd, LStrBuf(*data), *bytesRead, bytesRead, NULL)) + { + ret = GetLastError(); + *eof = (ret == ERROR_HANDLE_EOF || ret == ERROR_BROKEN_PIPE); + if (!*eof) + err = Win32ToLVErr(ret); + } + else + { + if (*bytesRead) + *eof = *bytesRead == 0; + } } #elif defined(Unix) ! ret = read((pipe_t)fd, LStrBuf(*data), *bytesRead) if (ret < 0) { *************** *** 356,362 **** ! if (!err && (bytes != *bytesRead)) { ! err = NumericArrayResize(uB, 1, &(UHandle)data, *bytesRead); LStrLen(*data) = *bytesRead; } --- 374,383 ---- ! if (bytesReq != *bytesRead) { ! if (err) ! NumericArrayResize(uB, 1, &(UHandle)data, *bytesRead); ! else ! err = NumericArrayResize(uB, 1, &(UHandle)data, *bytesRead); LStrLen(*data) = *bytesRead; } *************** *** 371,374 **** --- 392,402 ---- return mgArgErr; + /* NULL terminate the LabVIEW string so that the API functions can use + them a C strings */ + err = NumericArrayResize(uB, 1, (UHandle*)&data, LStrLen(*data) + 1); + if (err) + return err; + LStrBuf(*data)[LStrLen(*data)]; + #if defined(MSWin) if (!WriteFile((HANDLE)fd, LStrBuf(*data), LStrLen(*data), bytesWritten, NULL) ) |