@@ -196,11 +196,11 @@ static TYPE_FD sock_open(const char *fn)
196196
197197 fd = CreateNamedPipe (
198198 fn , /* pipe name */
199- PIPE_ACCESS_DUPLEX | /* read/write access */
200- FILE_FLAG_OVERLAPPED , /* async IO */
201- PIPE_TYPE_BYTE |
202- PIPE_READMODE_BYTE |
203- PIPE_WAIT ,
199+ PIPE_ACCESS_DUPLEX /* read/write access */
200+ | FILE_FLAG_OVERLAPPED , /* async IO */
201+ PIPE_TYPE_BYTE
202+ | PIPE_READMODE_BYTE
203+ | PIPE_WAIT ,
204204 PIPE_UNLIMITED_INSTANCES , /* max. instances */
205205 ST_SOCK_BUF_LEN , /* output buffer size */
206206 ST_SOCK_BUF_LEN , /* input buffer size */
@@ -236,11 +236,26 @@ static TYPE_FD sock_open(const char *fn)
236236static void sock_disconnect (conn_t * conn )
237237{
238238#ifndef WIN32
239+ # if 0
240+ if (VALID_FD (conn -> fd )) {
241+ FILE * f = fdopen (conn -> fd , 600 );
242+ if (f ) {
243+ upsdebugx (4 , "%s: flushing socket %d" , __func__ , (int )conn -> fd );
244+ setvbuf (f , NULL , _IONBF , 0 );
245+ fflush (f );
246+ }
247+ }
248+ # endif
239249 upsdebugx (3 , "%s: disconnecting socket %d" , __func__ , (int )conn -> fd );
240250 close (conn -> fd );
241251#else /* WIN32 */
242252 /* FIXME NUT_WIN32_INCOMPLETE not sure if this is the right way to close a connection */
243253 if (conn -> read_overlapped .hEvent != INVALID_HANDLE_VALUE ) {
254+ if (VALID_FD (conn -> fd )) {
255+ upsdebugx (4 , "%s: flushing named pipe handle %p" , __func__ , conn -> fd );
256+ FlushFileBuffers (conn -> fd );
257+ }
258+ upsdebugx (4 , "%s: closing not-invalid named pipe handle %p" , __func__ , conn -> fd );
244259 CloseHandle (conn -> read_overlapped .hEvent );
245260 conn -> read_overlapped .hEvent = INVALID_HANDLE_VALUE ;
246261 }
0 commit comments