~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to vio/vio.c

  • Committer: Brian Aker
  • Date: 2008-07-14 22:18:37 UTC
  • mfrom: (77.1.96 codestyle)
  • Revision ID: brian@tangent.org-20080714221837-oceoshx7fjkla9u3
Merge from Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 */
28
28
 
29
29
static void vio_init(Vio* vio, enum enum_vio_type type,
30
 
                     my_socket sd, uint32_t flags)
 
30
                     my_socket sd, HANDLE hPipe, uint flags)
31
31
{
32
32
#ifndef HAVE_VIO_READ_BUFF
33
33
  flags&= ~VIO_BUFFERED_READ;
34
34
#endif
35
 
  memset((char*) vio, 0, sizeof(*vio));
 
35
  bzero((char*) vio, sizeof(*vio));
36
36
  vio->type     = type;
37
37
  vio->sd       = sd;
 
38
  vio->hPipe    = hPipe;
 
39
  vio->localhost= flags & VIO_LOCALHOST;
38
40
  if ((flags & VIO_BUFFERED_READ) &&
39
41
      !(vio->read_buffer= (char*)my_malloc(VIO_READ_BUFFER_SIZE, MYF(MY_WME))))
40
42
    flags&= ~VIO_BUFFERED_READ;
59
61
/* Reset initialized VIO to use with another transport type */
60
62
 
61
63
void vio_reset(Vio* vio, enum enum_vio_type type,
62
 
               my_socket sd, uint flags)
 
64
               my_socket sd, HANDLE hPipe, uint flags)
63
65
{
64
66
  my_free(vio->read_buffer, MYF(MY_ALLOW_ZERO_PTR));
65
 
  vio_init(vio, type, sd, flags);
 
67
  vio_init(vio, type, sd, hPipe, flags);
66
68
}
67
69
 
68
70
 
74
76
 
75
77
  if ((vio = (Vio*) my_malloc(sizeof(*vio),MYF(MY_WME))))
76
78
  {
77
 
    vio_init(vio, type, sd, flags);
78
 
    sprintf(vio->desc, "TCP/IP (%d)", vio->sd);
 
79
    vio_init(vio, type, sd, 0, flags);
 
80
    sprintf(vio->desc,
 
81
            (vio->type == VIO_TYPE_SOCKET ? "socket (%d)" : "TCP/IP (%d)"),
 
82
            vio->sd);
 
83
#if !defined(NO_FCNTL_NONBLOCK)
79
84
    /*
80
85
      We call fcntl() to set the flags and then immediately read them back
81
86
      to make sure that we and the system are in agreement on the state of
88
93
    */
89
94
    fcntl(sd, F_SETFL, 0);
90
95
    vio->fcntl_mode= fcntl(sd, F_GETFL);
 
96
#elif defined(HAVE_SYS_IOCTL_H)                 /* hpux */
 
97
    /* Non blocking sockets doesn't work good on HPUX 11.0 */
 
98
    (void) ioctl(sd,FIOSNBIO,0);
 
99
    vio->fcntl_mode &= ~O_NONBLOCK;
 
100
#endif
91
101
  }
92
102
  return vio;
93
103
}
101
111
  if (vio->type != VIO_CLOSED)
102
112
    vio->vioclose(vio);
103
113
  my_free((uchar*) vio->read_buffer, MYF(MY_ALLOW_ZERO_PTR));
104
 
  my_free((uchar*) vio, MYF(0));
 
114
  my_free((uchar*) vio,MYF(0));
105
115
}
106
116
 
107
117