~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzleclient/net_serv.c

  • Committer: Monty Taylor
  • Date: 2009-02-08 11:11:30 UTC
  • mto: This revision was merged to the branch mainline in revision 852.
  • Revision ID: mordred@inaugust.com-20090208111130-futpwptxv5he3boe
Renamed non-prefixed things from libdrizzleclient to drizzleclient.

Show diffs side-by-side

added added

removed removed

Lines of Context:
75
75
  return(0);
76
76
}
77
77
 
78
 
bool net_init_sock(NET * net, int sock, int flags)
 
78
bool drizzleclient_net_init_sock(NET * net, int sock, int flags)
79
79
{
80
80
 
81
81
  Vio *drizzleclient_vio_tmp= drizzleclient_vio_new(sock, VIO_TYPE_TCPIP, flags);
99
99
  return false;
100
100
}
101
101
 
102
 
void net_end(NET *net)
 
102
void drizzleclient_net_end(NET *net)
103
103
{
104
104
  if (net->buff != NULL)
105
105
    free(net->buff);
107
107
  return;
108
108
}
109
109
 
110
 
void net_close(NET *net)
 
110
void drizzleclient_net_close(NET *net)
111
111
{
112
112
  if (net->vio != NULL)
113
113
  {
116
116
  }
117
117
}
118
118
 
119
 
bool net_peer_addr(NET *net, char *buf, uint16_t *port, size_t buflen)
 
119
bool drizzleclient_net_peer_addr(NET *net, char *buf, uint16_t *port, size_t buflen)
120
120
{
121
121
  return drizzleclient_vio_peer_addr(net->vio, buf, port, buflen);
122
122
}
123
123
 
124
 
void net_keepalive(NET *net, bool flag)
 
124
void drizzleclient_net_keepalive(NET *net, bool flag)
125
125
{
126
126
  drizzleclient_vio_keepalive(net->vio, flag);
127
127
}
128
128
 
129
 
int net_get_sd(NET *net)
 
129
int drizzleclient_net_get_sd(NET *net)
130
130
{
131
131
  return net->vio->sd;
132
132
}
133
133
 
134
 
bool net_should_close(NET *net)
 
134
bool drizzleclient_net_should_close(NET *net)
135
135
{
136
136
  return net->error || (net->vio == 0);
137
137
}
138
138
 
139
 
bool net_more_data(NET *net)
 
139
bool drizzleclient_net_more_data(NET *net)
140
140
{
141
141
  return (net->vio == 0 || net->vio->read_pos < net->vio->read_end);
142
142
}
143
143
 
144
144
/** Realloc the packet buffer. */
145
145
 
146
 
bool net_realloc(NET *net, size_t length)
 
146
bool drizzleclient_net_realloc(NET *net, size_t length)
147
147
{
148
148
  unsigned char *buff;
149
149
  size_t pkt_length;
209
209
   Read from socket until there is nothing more to read. Discard
210
210
   what is read.
211
211
 
212
 
   If there is anything when to read 'net_clear' is called this
 
212
   If there is anything when to read 'drizzleclient_net_clear' is called this
213
213
   normally indicates an error in the protocol.
214
214
 
215
215
   When connection is properly closed (for TCP it means with
220
220
   @param clear_buffer           if <> 0, then clear all data from comm buff
221
221
*/
222
222
 
223
 
void net_clear(NET *net, bool clear_buffer)
 
223
void drizzleclient_net_clear(NET *net, bool clear_buffer)
224
224
{
225
225
  if (clear_buffer)
226
226
  {
243
243
 
244
244
/** Flush write_buffer if not empty. */
245
245
 
246
 
bool net_flush(NET *net)
 
246
bool drizzleclient_net_flush(NET *net)
247
247
{
248
248
  bool error= 0;
249
249
  if (net->buff != net->write_pos)
250
250
  {
251
 
    error=net_real_write(net, net->buff,
 
251
    error=drizzleclient_net_real_write(net, net->buff,
252
252
                         (size_t) (net->write_pos - net->buff)) ? 1 : 0;
253
253
    net->write_pos=net->buff;
254
254
  }
331
331
*/
332
332
 
333
333
bool
334
 
net_write_command(NET *net,unsigned char command,
 
334
drizzleclient_net_write_command(NET *net,unsigned char command,
335
335
                  const unsigned char *header, size_t head_len,
336
336
                  const unsigned char *packet, size_t len)
337
337
{
365
365
  buff[3]= (unsigned char) net->pkt_nr++;
366
366
  return((net_write_buff(net, buff, header_size) ||
367
367
          (head_len && net_write_buff(net, header, head_len)) ||
368
 
          net_write_buff(net, packet, len) || net_flush(net)) ? 1 : 0 );
 
368
          net_write_buff(net, packet, len) || drizzleclient_net_flush(net)) ? 1 : 0 );
369
369
}
370
370
 
371
371
/**
383
383
   @param len        Length of packet
384
384
 
385
385
   @note
386
 
   The cached buffer can be sent as it is with 'net_flush()'.
 
386
   The cached buffer can be sent as it is with 'drizzleclient_net_flush()'.
387
387
   In this code we have to be careful to not send a packet longer than
388
 
   MAX_PACKET_LENGTH to net_real_write() if we are using the compressed
 
388
   MAX_PACKET_LENGTH to drizzleclient_net_real_write() if we are using the compressed
389
389
   protocol as we store the length of the compressed packet in 3 bytes.
390
390
 
391
391
   @retval
409
409
    {
410
410
      /* Fill up already used packet and write it */
411
411
      memcpy(net->write_pos,packet,left_length);
412
 
      if (net_real_write(net, net->buff,
 
412
      if (drizzleclient_net_real_write(net, net->buff,
413
413
                         (size_t) (net->write_pos - net->buff) + left_length))
414
414
        return 1;
415
415
      net->write_pos= net->buff;
425
425
      left_length= MAX_PACKET_LENGTH;
426
426
      while (len > left_length)
427
427
      {
428
 
        if (net_real_write(net, packet, left_length))
 
428
        if (drizzleclient_net_real_write(net, packet, left_length))
429
429
          return 1;
430
430
        packet+= left_length;
431
431
        len-= left_length;
432
432
      }
433
433
    }
434
434
    if (len > net->max_packet)
435
 
      return net_real_write(net, packet, len) ? 1 : 0;
 
435
      return drizzleclient_net_real_write(net, packet, len) ? 1 : 0;
436
436
    /* Send out rest of the blocks as full sized blocks */
437
437
  }
438
438
  memcpy(net->write_pos,packet,len);
454
454
  in the server, yield to another process and come back later.
455
455
*/
456
456
int
457
 
net_real_write(NET *net, const unsigned char *packet, size_t len)
 
457
drizzleclient_net_real_write(NET *net, const unsigned char *packet, size_t len)
458
458
{
459
459
  size_t length;
460
460
  const unsigned char *pos, *end;
718
718
      /* The necessary size of net->buff */
719
719
      if (helping >= net->max_packet)
720
720
      {
721
 
        if (net_realloc(net,helping))
 
721
        if (drizzleclient_net_realloc(net,helping))
722
722
        {
723
723
          len= packet_error;          /* Return error and close connection */
724
724
          goto end;
935
935
  @param net  clear the state of the argument
936
936
*/
937
937
 
938
 
void net_clear_error(NET *net)
 
938
void drizzleclient_drizzleclient_net_clear_error(NET *net)
939
939
{
940
940
  net->last_errno= 0;
941
941
  net->last_error[0]= '\0';
942
 
  strcpy(net->sqlstate, sqlstate_get_not_error());
 
942
  strcpy(net->sqlstate, drizzleclient_sqlstate_get_not_error());
943
943
}
944
944