1
/* Copyright (C) 2000 MySQL AB
2
Copyright (c) 2001, 2011, Oracle and/or its affiliates. All rights reserved.
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License
6
as published by the Free Software Foundation; version 2 of
7
9
This program is distributed in the hope that it will be useful,
8
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
12
GNU General Public License for more details.
12
14
You should have received a copy of the GNU General Public License
13
15
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
20
Note that we can't have assertion on file descriptors; The reason for
416
419
Finish pending IO on pipe. Honor wait timeout
418
static int pipe_complete_io(Vio* vio, char* buf, size_t size, DWORD timeout_millis)
421
static size_t pipe_complete_io(Vio* vio, char* buf, size_t size, DWORD timeout_ms)
423
426
DBUG_ENTER("pipe_complete_io");
425
ret= WaitForSingleObject(vio->pipe_overlapped.hEvent, timeout_millis);
428
ret= WaitForSingleObject(vio->pipe_overlapped.hEvent, timeout_ms);
427
430
WaitForSingleObjects will normally return WAIT_OBJECT_O (success, IO completed)
448
451
size_t vio_read_pipe(Vio * vio, uchar *buf, size_t size)
450
453
DWORD bytes_read;
451
455
DBUG_ENTER("vio_read_pipe");
452
456
DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf,
455
if (!ReadFile(vio->hPipe, buf, (DWORD)size, &bytes_read,
459
if (ReadFile(vio->hPipe, buf, (DWORD)size, &bytes_read,
456
460
&(vio->pipe_overlapped)))
458
466
if (GetLastError() != ERROR_IO_PENDING)
460
468
DBUG_PRINT("error",("ReadFile() returned last error %d",
461
469
GetLastError()));
462
470
DBUG_RETURN((size_t)-1);
464
bytes_read= pipe_complete_io(vio, buf, size,vio->read_timeout_millis);
472
retval= pipe_complete_io(vio, buf, size,vio->read_timeout_ms);
467
DBUG_PRINT("exit", ("%d", bytes_read));
468
DBUG_RETURN(bytes_read);
475
DBUG_PRINT("exit", ("%lld", (longlong)retval));
472
480
size_t vio_write_pipe(Vio * vio, const uchar* buf, size_t size)
474
482
DWORD bytes_written;
475
484
DBUG_ENTER("vio_write_pipe");
476
485
DBUG_PRINT("enter", ("sd: %d buf: 0x%lx size: %u", vio->sd, (long) buf,
479
if (!WriteFile(vio->hPipe, buf, (DWORD)size, &bytes_written,
488
if (WriteFile(vio->hPipe, buf, (DWORD)size, &bytes_written,
480
489
&(vio->pipe_overlapped)))
491
retval= bytes_written;
482
495
if (GetLastError() != ERROR_IO_PENDING)
484
497
DBUG_PRINT("vio_error",("WriteFile() returned last error %d",
485
498
GetLastError()));
486
499
DBUG_RETURN((size_t)-1);
488
bytes_written = pipe_complete_io(vio, (char *)buf, size,
489
vio->write_timeout_millis);
501
retval= pipe_complete_io(vio, (char *)buf, size, vio->write_timeout_ms);
492
DBUG_PRINT("exit", ("%d", bytes_written));
493
DBUG_RETURN(bytes_written);
504
DBUG_PRINT("exit", ("%lld", (longlong)retval));
516
528
void vio_win32_timeout(Vio *vio, uint which , uint timeout_sec)
518
DWORD timeout_millis;
520
532
Windows is measuring timeouts in milliseconds. Check for possible int
523
535
if (timeout_sec > UINT_MAX/1000)
524
timeout_millis= INFINITE;
536
timeout_ms= INFINITE;
526
timeout_millis= timeout_sec * 1000;
538
timeout_ms= timeout_sec * 1000;
528
540
/* which == 1 means "write", which == 0 means "read".*/
530
vio->write_timeout_millis= timeout_millis;
542
vio->write_timeout_ms= timeout_ms;
532
vio->read_timeout_millis= timeout_millis;
544
vio->read_timeout_ms= timeout_ms;
581
593
if (length > remain_local)
582
594
length = remain_local;
584
memcpy(current_postion,vio->shared_memory_pos,length);
596
memcpy(current_position,vio->shared_memory_pos,length);
586
598
vio->shared_memory_remain-=length;
587
599
vio->shared_memory_pos+=length;
588
current_postion+=length;
600
current_position+=length;
589
601
remain_local-=length;
591
603
if (!vio->shared_memory_remain)
632
644
int4store(vio->handle_map,sz);
633
645
pos = vio->handle_map + 4;
634
memcpy(pos,current_postion,sz);
646
memcpy(pos,current_position,sz);
648
current_position+=sz;
637
649
if (!SetEvent(vio->event_client_wrote))
638
650
DBUG_RETURN((size_t) -1);