~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/net_serv.c

  • Committer: Brian Aker
  • Date: 2008-07-18 20:10:26 UTC
  • mfrom: (51.3.29 remove-dbug)
  • Revision ID: brian@tangent.org-20080718201026-tto5golt0xhwqe4a
Merging in Jay's final patch on dbug.

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)
439
417
  int error;
440
418
 
441
419
  if (net->error == 2)
442
 
    DBUG_RETURN(-1);                            /* socket can't be used */
 
420
    return(-1);                         /* socket can't be used */
443
421
 
444
422
  net->reading_or_writing=2;
445
423
  if (net->compress)
454
432
      net->last_errno= ER_OUT_OF_RESOURCES;
455
433
      /* In the server, the error is reported by MY_WME flag. */
456
434
      net->reading_or_writing= 0;
457
 
      DBUG_RETURN(1);
 
435
      return(1);
458
436
    }
459
437
    memcpy(b+header_length,packet,len);
460
438
 
544
522
    error= setsockopt(net->vio->sd, SOL_SOCKET, SO_RCVTIMEO, 
545
523
                      &backtime, (socklen_t)sizeof(struct timeval));
546
524
 
547
 
  DBUG_RETURN(((int) (pos != end)));
 
525
  return(((int) (pos != end)));
548
526
}
549
527
 
550
528
 
610
588
      {
611
589
        bool interrupted = vio_should_retry(net->vio);
612
590
 
613
 
        DBUG_PRINT("info",("vio_read returned %ld  errno: %d",
614
 
                           (long) length, vio_errno(net->vio)));
615
591
        if (interrupted)
616
592
        {                                       /* Probably in MIT threads */
617
593
          if (retry_count++ < net->retry_count)
830
806
 
831
807
void my_net_set_read_timeout(NET *net, uint timeout)
832
808
{
833
 
  DBUG_ENTER("my_net_set_read_timeout");
834
 
  DBUG_PRINT("enter", ("timeout: %d", timeout));
835
809
  net->read_timeout= timeout;
836
810
  if (net->vio)
837
811
    vio_timeout(net->vio, 0, timeout);
838
 
  DBUG_VOID_RETURN;
 
812
  return;
839
813
}
840
814
 
841
815
 
842
816
void my_net_set_write_timeout(NET *net, uint timeout)
843
817
{
844
 
  DBUG_ENTER("my_net_set_write_timeout");
845
 
  DBUG_PRINT("enter", ("timeout: %d", timeout));
846
818
  net->write_timeout= timeout;
847
819
  if (net->vio)
848
820
    vio_timeout(net->vio, 1, timeout);
849
 
  DBUG_VOID_RETURN;
 
821
  return;
850
822
}