~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/net_serv.c

  • Committer: Jay Pipes
  • Date: 2008-07-17 17:54:00 UTC
  • mto: This revision was merged to the branch mainline in revision 182.
  • Revision ID: jay@mysql.com-20080717175400-xm2aazihjra8mdzq
Removal of DBUG from libdrizzle/ - Round 2

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
 
57
57
bool my_net_init(NET *net, Vio* vio)
58
58
{
59
 
  DBUG_ENTER("my_net_init");
60
59
  net->vio = vio;
61
60
  my_net_local_init(net);                       /* Set some limits */
62
61
  if (!(net->buff=(uchar*) my_malloc((size_t) net->max_packet+
63
62
                                     NET_HEADER_SIZE + COMP_HEADER_SIZE,
64
63
                                     MYF(MY_WME))))
65
 
    DBUG_RETURN(1);
 
64
    return(1);
66
65
  net->buff_end=net->buff+net->max_packet;
67
66
  net->error=0; net->return_status=0;
68
67
  net->pkt_nr=net->compress_pkt_nr=0;
78
77
    net->fd  = vio_fd(vio);                     /* For perl DBI/DBD */
79
78
    vio_fastsend(vio);
80
79
  }
81
 
  DBUG_RETURN(0);
 
80
  return(0);
82
81
}
83
82
 
84
83
 
85
84
void net_end(NET *net)
86
85
{
87
 
  DBUG_ENTER("net_end");
88
86
  my_free(net->buff,MYF(MY_ALLOW_ZERO_PTR));
89
87
  net->buff=0;
90
 
  DBUG_VOID_RETURN;
 
88
  return;
91
89
}
92
90
 
93
91
 
97
95
{
98
96
  uchar *buff;
99
97
  size_t pkt_length;
100
 
  DBUG_ENTER("net_realloc");
101
 
  DBUG_PRINT("enter",("length: %lu", (ulong) length));
102
98
 
103
99
  if (length >= net->max_packet_size)
104
100
  {
105
 
    DBUG_PRINT("error", ("Packet too large. Max size: %lu",
106
 
                         net->max_packet_size));
107
101
    /* @todo: 1 and 2 codes are identical. */
108
102
    net->error= 1;
109
103
    net->last_errno= ER_NET_PACKET_TOO_LARGE;
110
 
    DBUG_RETURN(1);
 
104
    return(1);
111
105
  }
112
106
  pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1); 
113
107
  /*
122
116
    net->error= 1;
123
117
    net->last_errno= ER_OUT_OF_RESOURCES;
124
118
    /* In the server the error is reported by MY_WME flag. */
125
 
    DBUG_RETURN(1);
 
119
    return(1);
126
120
  }
127
121
  net->buff=net->write_pos=buff;
128
122
  net->buff_end=buff+(net->max_packet= (ulong) pkt_length);
129
 
  DBUG_RETURN(0);
 
123
  return(0);
130
124
}
131
125
 
132
126
 
179
173
{
180
174
  size_t count;
181
175
  int32_t ready;
182
 
  DBUG_ENTER("net_clear");
183
176
 
184
177
  if (clear_buffer)
185
178
  {
187
180
    {
188
181
      /* The socket is ready */
189
182
      if ((long) (count= vio_read(net->vio, net->buff,
190
 
                                  (size_t) net->max_packet)) > 0)
191
 
      {
192
 
        DBUG_PRINT("info",("skipped %ld bytes from file: %s",
193
 
                           (long) count, vio_description(net->vio)));
194
 
      }
195
 
      else
196
 
      {
197
 
        DBUG_PRINT("info",("socket ready but only EOF to read - disconnected"));
 
183
                                  (size_t) net->max_packet)) <= 0)
 
184
      {
198
185
        net->error= 2;
199
186
        break;
200
187
      }
202
189
  }
203
190
  net->pkt_nr=net->compress_pkt_nr=0;           /* Ready for new command */
204
191
  net->write_pos=net->buff;
205
 
  DBUG_VOID_RETURN;
 
192
  return;
206
193
}
207
194
 
208
195
 
211
198
bool net_flush(NET *net)
212
199
{
213
200
  my_bool error= 0;
214
 
  DBUG_ENTER("net_flush");
215
201
  if (net->buff != net->write_pos)
216
202
  {
217
203
    error=test(net_real_write(net, net->buff,
221
207
  /* Sync packet number if using compression */
222
208
  if (net->compress)
223
209
    net->pkt_nr=net->compress_pkt_nr;
224
 
  DBUG_RETURN(error);
 
210
  return(error);
225
211
}
226
212
 
227
213
 
266
252
  buff[3]= (uchar) net->pkt_nr++;
267
253
  if (net_write_buff(net, buff, NET_HEADER_SIZE))
268
254
    return 1;
269
 
#ifndef DEBUG_DATA_PACKETS
270
 
  DBUG_DUMP("packet_header", buff, NET_HEADER_SIZE);
271
 
#endif
272
255
  return test(net_write_buff(net,packet,len));
273
256
}
274
257
 
307
290
  ulong length=len+1+head_len;                  /* 1 extra byte for command */
308
291
  uchar buff[NET_HEADER_SIZE+1];
309
292
  uint header_size=NET_HEADER_SIZE+1;
310
 
  DBUG_ENTER("net_write_command");
311
 
  DBUG_PRINT("enter",("length: %lu", (ulong) len));
312
293
 
313
294
  buff[4]=command;                              /* For first packet */
314
295
 
323
304
      if (net_write_buff(net, buff, header_size) ||
324
305
          net_write_buff(net, header, head_len) ||
325
306
          net_write_buff(net, packet, len))
326
 
        DBUG_RETURN(1);
 
307
        return(1);
327
308
      packet+= len;
328
309
      length-= MAX_PACKET_LENGTH;
329
310
      len= MAX_PACKET_LENGTH;
334
315
  }
335
316
  int3store(buff,length);
336
317
  buff[3]= (uchar) net->pkt_nr++;
337
 
  DBUG_RETURN(test(net_write_buff(net, buff, header_size) ||
 
318
  return(test(net_write_buff(net, buff, header_size) ||
338
319
                   (head_len && net_write_buff(net, header, head_len)) ||
339
320
                   net_write_buff(net, packet, len) || net_flush(net)));
340
321
}
374
355
  else
375
356
    left_length= (ulong) (net->buff_end - net->write_pos);
376
357
 
377
 
#ifdef DEBUG_DATA_PACKETS
378
 
  DBUG_DUMP("data", packet, len);
379
 
#endif
380
358
  if (len > left_length)
381
359
  {
382
360
    if (net->write_pos != net->buff)
435
413
  uint retry_count= 0;
436
414
 
437
415
  if (net->error == 2)
438
 
    DBUG_RETURN(-1);                            /* socket can't be used */
 
416
    return(-1);                         /* socket can't be used */
439
417
 
440
418
  net->reading_or_writing=2;
441
419
  if (net->compress)
450
428
      net->last_errno= ER_OUT_OF_RESOURCES;
451
429
      /* In the server, the error is reported by MY_WME flag. */
452
430
      net->reading_or_writing= 0;
453
 
      DBUG_RETURN(1);
 
431
      return(1);
454
432
    }
455
433
    memcpy(b+header_length,packet,len);
456
434
 
514
492
    my_free((char*) packet,MYF(0));
515
493
  net->reading_or_writing=0;
516
494
 
517
 
  DBUG_RETURN(((int) (pos != end)));
 
495
  return(((int) (pos != end)));
518
496
}
519
497
 
520
498
 
580
558
      {
581
559
        bool interrupted = vio_should_retry(net->vio);
582
560
 
583
 
        DBUG_PRINT("info",("vio_read returned %ld  errno: %d",
584
 
                           (long) length, vio_errno(net->vio)));
585
561
        if (interrupted)
586
562
        {                                       /* Probably in MIT threads */
587
563
          if (retry_count++ < net->retry_count)
800
776
 
801
777
void my_net_set_read_timeout(NET *net, uint timeout)
802
778
{
803
 
  DBUG_ENTER("my_net_set_read_timeout");
804
 
  DBUG_PRINT("enter", ("timeout: %d", timeout));
805
779
  net->read_timeout= timeout;
806
780
  if (net->vio)
807
781
    vio_timeout(net->vio, 0, timeout);
808
 
  DBUG_VOID_RETURN;
 
782
  return;
809
783
}
810
784
 
811
785
 
812
786
void my_net_set_write_timeout(NET *net, uint timeout)
813
787
{
814
 
  DBUG_ENTER("my_net_set_write_timeout");
815
 
  DBUG_PRINT("enter", ("timeout: %d", timeout));
816
788
  net->write_timeout= timeout;
817
789
  if (net->vio)
818
790
    vio_timeout(net->vio, 1, timeout);
819
 
  DBUG_VOID_RETURN;
 
791
  return;
820
792
}