~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/internal/iocache.cc

  • Committer: Brian Aker
  • Date: 2010-11-06 19:38:41 UTC
  • mto: This revision was merged to the branch mainline in revision 1910.
  • Revision ID: brian@tangent.org-20101106193841-exc9cc3qc515zhev
Encapsulation of IO_CACHE.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
namespace internal
29
29
{
30
30
 
31
 
        /*
32
 
        ** Open tempfile cached by IO_CACHE
33
 
        ** Should be used when no seeks are done (only reinit_io_buff)
34
 
        ** Return false if cache is inited ok
35
 
        ** The actual file is created when the IO_CACHE buffer gets filled
36
 
        ** If dir is not given, use TMPDIR.
37
 
        */
 
31
/*
 
32
** Open tempfile cached by st_io_cache
 
33
** Should be used when no seeks are done (only reinit_io_buff)
 
34
** Return false if cache is inited ok
 
35
** The actual file is created when the st_io_cache buffer gets filled
 
36
** If dir is not given, use TMPDIR.
 
37
*/
38
38
 
39
 
bool open_cached_file(IO_CACHE *cache, const char* dir, const char *prefix,
40
 
                         size_t cache_size, myf cache_myflags)
 
39
bool open_cached_file(st_io_cache *cache, const char *dir_arg, const char *prefix_arg,
 
40
                      size_t cache_size_arg, myf cache_myflags)
41
41
{
42
 
  cache->dir=    dir ? strdup(dir) : (char*) 0;
43
 
  cache->prefix= (prefix ? strdup(prefix) :
44
 
                 (char*) 0);
 
42
  cache->dir=    dir_arg ? strdup(dir_arg) : (char*) 0;
 
43
  cache->prefix= (prefix_arg ? strdup(prefix_arg) : (char*) 0);
 
44
 
45
45
  if ((cache->dir == NULL) || (cache->prefix == NULL))
46
46
    return true;
47
 
  cache->file_name=0;
48
 
  cache->buffer=0;                              /* Mark that not open */
49
 
  if (!init_io_cache(cache,-1,cache_size,WRITE_CACHE,0L,0,
50
 
                     MYF(cache_myflags | MY_NABP)))
 
47
 
 
48
  cache->file_name= 0;
 
49
  cache->buffer= 0;                             /* Mark that not open */
 
50
  if (not cache->init_io_cache(-1, cache_size_arg,WRITE_CACHE,0L,0, MYF(cache_myflags | MY_NABP)))
51
51
  {
52
52
    return false;
53
53
  }
54
54
  free(cache->dir);
55
55
  free(cache->prefix);
 
56
 
56
57
  return true;
57
58
}
58
59
 
59
 
        /* Create the temporary file */
 
60
/* Create the temporary file */
60
61
 
61
 
bool real_open_cached_file(IO_CACHE *cache)
 
62
bool st_io_cache::real_open_cached_file()
62
63
{
63
64
  char name_buff[FN_REFLEN];
64
 
  int error=1;
65
 
  if ((cache->file=create_temp_file(name_buff, cache->dir, cache->prefix, MYF(MY_WME))) >= 0)
 
65
 
 
66
  if ((file= create_temp_file(name_buff, dir, prefix, MYF(MY_WME))) >= 0)
66
67
  {
67
 
    error=0;
68
68
    my_delete(name_buff,MYF(MY_WME | ME_NOINPUT));
 
69
    return false;
69
70
  }
70
 
  return(error);
 
71
 
 
72
  return true;
71
73
}
72
74
 
73
75
 
74
 
void close_cached_file(IO_CACHE *cache)
 
76
void st_io_cache::close_cached_file()
75
77
{
76
 
  if (my_b_inited(cache))
 
78
  if (my_b_inited(this))
77
79
  {
78
 
    int file=cache->file;
79
 
    cache->file= -1;                            /* Don't flush data */
80
 
    (void) end_io_cache(cache);
81
 
    if (file >= 0)
 
80
    int _file= file;
 
81
    file= -1;                           /* Don't flush data */
 
82
    (void) end_io_cache();
 
83
    if (_file >= 0)
82
84
    {
83
 
      (void) my_close(file,MYF(0));
 
85
      (void) my_close(_file, MYF(0));
84
86
#ifdef CANT_DELETE_OPEN_FILES
85
 
      if (cache->file_name)
 
87
      if (file_name)
86
88
      {
87
 
        (void) my_delete(cache->file_name,MYF(MY_WME | ME_NOINPUT));
88
 
        free(cache->file_name);
 
89
        (void) my_delete(file_name, MYF(MY_WME | ME_NOINPUT));
 
90
        free(file_name);
89
91
      }
90
92
#endif
91
93
    }
92
 
    free(cache->dir);
93
 
    free(cache->prefix);
 
94
    free(dir);
 
95
    free(prefix);
94
96
  }
95
 
  return;
96
97
}
97
98
 
98
99
} /* namespace internal */