~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbms/src/cslib/CSStream.cc

Merge Joe, plus I updated the tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
 
1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
2
2
 *
3
3
 * PrimeBase Media Stream for MySQL
4
4
 *
14
14
 *
15
15
 * You should have received a copy of the GNU General Public License
16
16
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
18
 *
19
19
 * Original author: Paul McCullagh (H&G2JCtL)
20
20
 * Continued development: Barry Leslie
39
39
#include "CSStream.h"
40
40
#include "CSGlobal.h"
41
41
 
 
42
using namespace std;
 
43
 
42
44
/*
43
45
 * ---------------------------------------------------------------
44
46
 * STREAM UTILITIES
181
183
        return_(size == 0 ? -1 : (int) ch);
182
184
}
183
185
 
184
 
void CSFileInputStream::reset()
185
 
{
186
 
        iReadOffset = 0;
187
 
}
188
 
 
189
 
const char *CSFileInputStream::identify()
190
 
{
191
 
        return iFile->myFilePath->getCString();
192
 
}
 
186
void CSFileInputStream::reset() {iReadOffset = 0;}
193
187
 
194
188
int CSFileInputStream::peek()
195
189
{
273
267
        exit_();
274
268
}
275
269
 
276
 
void CSFileOutputStream::reset()
277
 
{
278
 
        iWriteOffset = 0;
279
 
}
280
 
 
281
 
const char *CSFileOutputStream::identify()
282
 
{
283
 
        return iFile->myFilePath->getCString();
284
 
}
 
270
void CSFileOutputStream::reset() {iWriteOffset = 0;}
285
271
 
286
272
void CSFileOutputStream::close()
287
273
{
358
344
        exit_();
359
345
}
360
346
 
361
 
const char *CSSocketInputStream::identify()
362
 
{
363
 
        return iSocket->identify();
364
 
}
365
347
 
366
348
CSSocketInputStream *CSSocketInputStream::newStream(CSSocket *s)
367
349
{
421
403
        exit_();
422
404
}
423
405
 
424
 
const char *CSSocketOutputStream::identify()
425
 
{
426
 
        return iSocket->identify();
427
 
}
428
 
 
429
406
CSSocketOutputStream *CSSocketOutputStream::newStream(CSSocket *s)
430
407
{
431
408
        CSSocketOutputStream *str;
513
490
        iStream->reset();
514
491
}
515
492
 
516
 
const char *CSBufferedInputStream::identify()
517
 
{
518
 
        return iStream->identify();
519
 
}
520
 
 
521
493
CSBufferedInputStream *CSBufferedInputStream::newStream(CSInputStream* i)
522
494
{
523
495
        CSBufferedInputStream *s;
552
524
{
553
525
        size_t tfer;
554
526
 
555
 
        // If the length of the data being written is greater than half
556
 
        // the buffer size then the data is written directly through
557
 
        // with out buffering.
558
527
        enter_();
559
 
        if (iBuffTotal < CS_STREAM_BUFFER_SIZE/2) {
 
528
        if (iBuffTotal < CS_STREAM_BUFFER_SIZE) {
560
529
                tfer = CS_STREAM_BUFFER_SIZE - iBuffTotal;
561
530
                
562
531
                if (tfer > len)
568
537
        }
569
538
        if (len > 0) {
570
539
                flush();
571
 
                if (len > CS_STREAM_BUFFER_SIZE/2)
 
540
                if (len > CS_STREAM_BUFFER_SIZE)
572
541
                        iStream->write(b, len);
573
542
                else {
574
543
                        memcpy(iBuffer, b, len);
580
549
 
581
550
void CSBufferedOutputStream::flush()
582
551
{
583
 
        size_t len;
584
 
 
585
552
        enter_();
586
 
        if ((len = iBuffTotal)) {
587
 
                /* Discard the contents of the buffer
588
 
                 * if flush fails, because we do
589
 
                 * not know how much was written anyway!
590
 
                 */
 
553
        if (iBuffTotal > 0) {
 
554
                iStream->write((char *) iBuffer, iBuffTotal);
591
555
                iBuffTotal = 0;
592
 
                iStream->write((char *) iBuffer, len);
593
556
        }
594
557
        exit_();
595
558
}
610
573
        iStream->reset();
611
574
}
612
575
 
613
 
const char *CSBufferedOutputStream::identify()
614
 
{
615
 
        return iStream->identify();
616
 
}
617
 
 
618
576
CSBufferedOutputStream *CSBufferedOutputStream::newStream(CSOutputStream* i)
619
577
{
620
578
        CSBufferedOutputStream *s;
700
658
        iMemSpace = iMemTotal;
701
659
}
702
660
 
703
 
const char *CSMemoryOutputStream::identify()
704
 
{
705
 
        return "memory stream";
706
 
}
707
 
 
708
661
/*
709
662
 * ---------------------------------------------------------------
710
663
 * STATIC (user) MEMORY OUTPUT STREAM
738
691
 * Callback InPUT STREAM
739
692
 */
740
693
 
741
 
CSCallbackInputStream *CSCallbackInputStream::newStream(CSStreamReadCallbackFunc in_callback, void *user_data)
 
694
CSCallbackInputStream *CSCallbackInputStream::newStream(CSStreamReadCallbackFunc callback, void *user_data)
742
695
{
743
696
        CSCallbackInputStream *s;
744
697
 
746
699
                CSException::throwOSError(CS_CONTEXT, ENOMEM);
747
700
        }
748
701
        
749
 
        s->callback = in_callback;
 
702
        s->callback = callback;
750
703
        s->cb_data = user_data;
751
704
        return s;
752
705
}