~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to storage/archive/azio.cc

Merged from Toru - removal of my_time_t.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
 
12
12
/* @(#) $Id$ */
13
13
 
14
 
#include <config.h>
15
 
 
16
14
#include "azio.h"
17
15
 
18
 
#include <fcntl.h>
 
16
#include <stdio.h>
 
17
#include <string.h>
 
18
#include <stdlib.h>
 
19
#include <assert.h>
19
20
#include <unistd.h>
20
21
 
21
 
#include <cstdio>
22
 
#include <cstring>
23
 
#include <cstdlib>
24
 
#include <cassert>
25
 
 
26
 
using namespace drizzled;
27
 
 
28
22
static int const az_magic[3] = {0xfe, 0x03, 0x01}; /* az magic header */
29
23
 
30
24
static unsigned int azwrite(azio_stream *s, void *buf, unsigned int len);
43
37
static void do_aio_cleanup(azio_stream *s);
44
38
#endif
45
39
 
46
 
extern "C" pthread_handler_t run_task(void *p);
47
 
 
48
 
extern "C" pthread_handler_t run_task(void *p)
 
40
extern "C"
 
41
pthread_handler_t run_task(void *p)
49
42
{
50
43
  int fd;
51
44
  char *buffer;
52
45
  size_t offset;
53
46
  azio_stream *s= (azio_stream *)p;
54
47
 
 
48
  my_thread_init();
 
49
 
55
50
  while (1)
56
51
  {
57
52
    pthread_mutex_lock(&s->container.thresh_mutex);
75
70
    pthread_mutex_unlock(&s->container.thresh_mutex);
76
71
  }
77
72
 
 
73
  my_thread_end();
 
74
 
78
75
  return 0;
79
76
}
80
77
 
159
156
  int err;
160
157
  int level = Z_DEFAULT_COMPRESSION ; /* compression level */
161
158
  int strategy = Z_DEFAULT_STRATEGY; /* compression strategy */
162
 
  int fd= -1;
 
159
  File fd= -1;
163
160
 
164
161
  memset(s, 0, sizeof(azio_stream));
165
162
 
225
222
  s->stream.avail_out = AZ_BUFSIZE_WRITE;
226
223
 
227
224
  errno = 0;
228
 
  s->file = fd < 0 ? internal::my_open(path, Flags, MYF(0)) : fd;
 
225
  s->file = fd < 0 ? my_open(path, Flags, MYF(0)) : fd;
229
226
#ifdef AZIO_AIO
230
227
  s->container.fd= s->file;
231
228
#endif
437
434
    if (s->mode == 'w')
438
435
    {
439
436
      err = deflateEnd(&(s->stream));
440
 
      internal::my_sync(s->file, MYF(0));
 
437
      my_sync(s->file, MYF(0));
441
438
    }
442
439
    else if (s->mode == 'r')
443
440
      err = inflateEnd(&(s->stream));
445
442
 
446
443
  do_aio_cleanup(s);
447
444
 
448
 
  if (s->file > 0 && internal::my_close(s->file, MYF(0)))
 
445
  if (s->file > 0 && my_close(s->file, MYF(0)))
449
446
      err = Z_ERRNO;
450
447
 
451
448
  s->file= -1;
459
456
  Reads the given number of uncompressed bytes from the compressed file.
460
457
  azread returns the number of bytes actually read (0 for end of file).
461
458
*/
462
 
/*
463
 
   This function is legacy, do not use.
464
 
 
465
 
     Reads the given number of uncompressed bytes from the compressed file.
466
 
   If the input file was not in gzip format, gzread copies the given number
467
 
   of bytes into the buffer.
468
 
     gzread returns the number of uncompressed bytes actually read (0 for
469
 
   end of file, -1 for error).
470
 
*/
471
 
static unsigned int azread_internal( azio_stream *s, voidp buf, unsigned int len, int *error)
 
459
unsigned int azread_internal( azio_stream *s, voidp buf, unsigned int len, int *error)
472
460
{
473
461
  Bytef *start = (Bytef*)buf; /* starting point for crc computation */
474
462
  Byte  *next_out; /* == stream.next_out but not forced far (for MSDOS) */
754
742
    err= do_flush(s, flush);
755
743
 
756
744
    if (err) return err;
757
 
    internal::my_sync(s->file, MYF(0));
 
745
    my_sync(s->file, MYF(0));
758
746
    return  s->z_err == Z_STREAM_END ? Z_OK : s->z_err;
759
747
  }
760
748
}
901
889
  for (n = 0; n < 4; n++)
902
890
  {
903
891
    buffer[0]= (int)(x & 0xff);
904
 
    size_t ret= pwrite(s->file, buffer, 1, s->pos);
905
 
    assert(ret == 1);
 
892
    assert(pwrite(s->file, buffer, 1, s->pos)==1);
906
893
    s->pos++;
907
894
    x >>= 8;
908
895
  }
971
958
  Though this was added to support MySQL's FRM file, anything can be
972
959
  stored in this location.
973
960
*/
974
 
int azwrite_frm(azio_stream *s, const char *blob, unsigned int length)
 
961
int azwrite_frm(azio_stream *s, char *blob, unsigned int length)
975
962
{
976
963
  if (s->mode == 'r')
977
964
    return 1;
1006
993
/*
1007
994
  Simple comment field
1008
995
*/
1009
 
int azwrite_comment(azio_stream *s, const char *blob, unsigned int length)
 
996
int azwrite_comment(azio_stream *s, char *blob, unsigned int length)
1010
997
{
1011
998
  if (s->mode == 'r')
1012
 
    return -1;
 
999
    return 1;
1013
1000
 
1014
1001
  if (s->rows > 0)
1015
 
    return -1;
 
1002
    return 1;
1016
1003
 
1017
1004
  s->comment_start_pos= (uint) s->start;
1018
1005
  s->comment_length= length;
1021
1008
  ssize_t r= pwrite(s->file, (unsigned char*) blob,
1022
1009
                    s->comment_length, s->comment_start_pos);
1023
1010
  if (r != (ssize_t)s->comment_length)
1024
 
    return -1;
 
1011
    return r;
1025
1012
 
1026
1013
  write_header(s);
1027
1014
  s->pos= (size_t)lseek(s->file, 0, SEEK_END);
1072
1059
    }
1073
1060
    s->pos+= s->stream.avail_in;
1074
1061
    s->inbuf= (Byte *)s->container.buffer;
1075
 
    /* We only azio_read when we know there is more data to be read */
 
1062
    /* We only aio_read when we know there is more data to be read */
1076
1063
    if (s->pos >= s->check_point)
1077
1064
    {
1078
1065
      s->aio_inited= 0;