ucommon  7.0.0
About: GNU uCommon C++ is a portable and optimized class framework for writing C++ applications that need to use threads and support concurrent synchronization, and that use sockets, XML parsing, object serialization, thread-optimized string and data structure classes, etc..
  Fossies Dox: ucommon-7.0.0.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

stream.cpp
Go to the documentation of this file.
1 // Copyright (C) 2006-2014 David Sugar, Tycho Softworks.
2 // Copyright (C) 2015 Cherokees of Idaho.
3 //
4 // This file is part of GNU uCommon C++.
5 //
6 // GNU uCommon C++ is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU Lesser General Public License as published
8 // by the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // GNU uCommon C++ is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public License
17 // along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
18 
19 #ifndef UCOMMON_SYSRUNTIME
20 
21 #include <ucommon-config.h>
22 #include <ucommon/export.h>
23 #include <ucommon/thread.h>
24 #include <ucommon/socket.h>
25 #include <ucommon/string.h>
26 #include <ucommon/shell.h>
27 #include <ucommon/stream.h>
28 #include <stdarg.h>
29 
30 #ifndef _MSWINDOWS_
31 #include <netinet/tcp.h>
32 #include <arpa/inet.h>
33 #include <sys/socket.h>
34 #include <sys/wait.h>
35 #ifdef HAVE_FCNTL_H
36 #include <fcntl.h>
37 #endif
38 #endif
39 
40 #ifdef HAVE_SYS_RESOURCE_H
41 #include <sys/time.h>
42 #include <sys/resource.h>
43 #endif
44 
45 namespace ucommon {
46 using std::iostream;
47 using std::streambuf;
48 using std::ios;
49 
50 #undef EOF
51 #define EOF std::streambuf::traits_type::eof()
52 #define IS_EOF(x) std::streambuf::traits_type::eq_int_type(x, EOF)
53 #define GET(x) std::streambuf::traits_type::to_int_type(x)
54 #define PUT(x) std::streambuf::traits_type::to_char_type(x)
55 
57 streambuf(), iostream((streambuf *)this)
58 {
59  bufsize = 0;
60  gbuf = pbuf = NULL;
61 }
62 
64 {
65  int ret = underflow();
66 
67  if(IS_EOF(ret))
68  return EOF;
69 
70  if (bufsize != 1)
71  gbump(1);
72 
73  return ret;
74 }
75 
76 void StreamBuffer::allocate(size_t size)
77 {
78  if(gbuf)
79  delete[] gbuf;
80 
81  if(pbuf)
82  delete[] pbuf;
83 
84  gbuf = pbuf = NULL;
85 
86  if(size < 2) {
87  bufsize = 1;
88  return;
89  }
90 
91  gbuf = new char[size];
92  pbuf = new char[size];
93  assert(gbuf != NULL && pbuf != NULL);
94  bufsize = size;
95  clear();
96 #if (defined(__GNUC__) && (__GNUC__ < 3)) && !defined(MSWINDOWS) && !defined(STLPORT)
97  setb(gbuf, gbuf + size, 0);
98 #endif
99  setg(gbuf, gbuf + size, gbuf + size);
100  setp(pbuf, pbuf + size);
101 }
102 
104 {
105  if(gbuf)
106  delete[] gbuf;
107 
108  if(pbuf)
109  delete[] pbuf;
110 
111  gbuf = pbuf = NULL;
112  bufsize = 0;
113  clear();
114 }
115 
117 {
118  if(!bufsize)
119  return 0;
120 
121  overflow(EOF);
122  setg(gbuf, gbuf + bufsize, gbuf + bufsize);
123  return 0;
124 }
125 
127 StreamBuffer()
128 {
129  so = Socket::create(Socket::family(copy.so), SOCK_STREAM, IPPROTO_TCP);
130  timeout = copy.timeout;
131 }
132 
134 StreamBuffer()
135 {
136  so = Socket::create(family, SOCK_STREAM, IPPROTO_TCP);
137  timeout = tv;
138 }
139 
140 tcpstream::tcpstream(Socket::address& list, unsigned segsize, timeout_t tv) :
141 StreamBuffer()
142 {
143  so = Socket::create(list.family(), SOCK_STREAM, IPPROTO_TCP);
144  timeout = tv;
145  open(list);
146 }
147 
148 tcpstream::tcpstream(const TCPServer *server, unsigned segsize, timeout_t tv) :
149 StreamBuffer()
150 {
151  so = server->accept();
152  timeout = tv;
153  if(so == INVALID_SOCKET) {
154  clear(ios::failbit | rdstate());
155  return;
156  }
157  allocate(segsize);
158 }
159 
161 {
163 }
164 
166 {
169 }
170 
171 #ifndef MSG_WAITALL
172 #define MSG_WAITALL 0
173 #endif
174 
176 {
177  if(!timeout)
178  return true;
179 
180  return Socket::wait(so, timeout);
181 }
182 
183 ssize_t tcpstream::_read(char *buffer, size_t size)
184 {
185  return Socket::recvfrom(so, buffer, size, MSG_WAITALL);
186 }
187 
188 ssize_t tcpstream::_write(const char *buffer, size_t size)
189 {
190  return Socket::sendto(so, buffer, size);
191 }
192 
194 {
195  ssize_t rlen = 1;
196  char ch;
197 
198  if(bufsize == 1) {
199  if(!_wait()) {
200  clear(ios::failbit | rdstate());
201  return EOF;
202  }
203  else
204  rlen = _read(&ch, 1);
205  if(rlen < 1) {
206  if(rlen < 0)
207  reset();
208  return EOF;
209  }
210  return GET(ch);
211  }
212 
213  if(!gptr())
214  return EOF;
215 
216  if(gptr() < egptr())
217  return GET(*gptr());
218 
219  rlen = (ssize_t)((gbuf + bufsize) - eback());
220  if(!_wait()) {
221  clear(ios::failbit | rdstate());
222  return EOF;
223  }
224  else {
225  rlen = _read(eback(), rlen);
226  }
227  if(rlen < 1) {
228 // clear(ios::failbit | rdstate());
229  if(rlen < 0)
230  reset();
231  else
232  clear(ios::failbit | rdstate());
233  return EOF;
234  }
235 
236  setg(eback(), eback(), eback() + rlen);
237  return GET(*gptr());
238 }
239 
241 {
242  char ch;
243  ssize_t rlen, req;
244 
245  if(bufsize == 1) {
246  if(IS_EOF(c))
247  return EOF;
248 
249  ch = PUT(c);
250  rlen = _write((const char *)&ch, 1);
251  if(rlen < 1) {
252  if(rlen < 0)
253  reset();
254  return EOF;
255  }
256  else
257  return c;
258  }
259 
260  if(!pbase())
261  return EOF;
262 
263  req = (ssize_t)(pptr() - pbase());
264  if(req) {
265  rlen = _write(pbase(), req);
266  if(rlen < 1) {
267  if(rlen < 0)
268  reset();
269  return EOF;
270  }
271  req -= rlen;
272  }
273  // if write "partial", rebuffer remainder
274 
275  if(req)
276 // memmove(pbuf, pptr() + rlen, req);
277  memmove(pbuf, pbuf + rlen, req);
278  setp(pbuf, pbuf + bufsize);
279  pbump(req);
280 
281  if(c != EOF) {
282  *pptr() = PUT(c);
283  pbump(1);
284  }
285  return c;
286 }
287 
288 void tcpstream::open(Socket::address& list, unsigned mss)
289 {
290  if(bufsize)
291  close(); // close if existing is open...
292 
293  if(Socket::connectto(so, *list))
294  return;
295 
296  allocate(mss);
297 }
298 
299 void tcpstream::open(const char *host, const char *service, unsigned mss)
300 {
301  if(bufsize)
302  close();
303 
304  struct addrinfo *list = Socket::query(host, service, SOCK_STREAM, 0);
305  if(!list)
306  return;
307 
308  if(Socket::connectto(so, list)) {
309  Socket::release(list);
310  return;
311  }
312 
313  Socket::release(list);
314  allocate(mss);
315 }
316 
318 {
319  if(!bufsize)
320  return;
321 
322  if(gbuf)
323  delete[] gbuf;
324 
325  if(pbuf)
326  delete[] pbuf;
327 
328  gbuf = pbuf = NULL;
329  bufsize = 0;
330  clear();
332 }
333 
335 {
336  if(!bufsize)
337  return;
338 
339  sync();
340 
341  if(gbuf)
342  delete[] gbuf;
343 
344  if(pbuf)
345  delete[] pbuf;
346 
347  gbuf = pbuf = NULL;
348  bufsize = 0;
349  clear();
351 }
352 
353 void tcpstream::allocate(unsigned mss)
354 {
355  unsigned size = mss;
356  unsigned max = 0;
357 #ifdef TCP_MAXSEG
358  socklen_t alen = sizeof(max);
359 #endif
360 
361  if(mss == 1)
362  goto allocate;
363 
364 #ifdef TCP_MAXSEG
365  if(mss)
366  setsockopt(so, IPPROTO_TCP, TCP_MAXSEG, (char *)&max, sizeof(max));
367  getsockopt(so, IPPROTO_TCP, TCP_MAXSEG, (char *)&max, &alen);
368 #endif
369 
370  if(max && max < mss)
371  mss = max;
372 
373  if(!mss) {
374  if(max)
375  mss = max;
376  else
377  mss = 536;
378  goto allocate;
379  }
380 
381 #ifdef TCP_MAXSEG
382  setsockopt(so, IPPROTO_TCP, TCP_MAXSEG, (char *)&mss, sizeof(mss));
383 #endif
384 
385  if(mss < 80)
386  mss = 80;
387 
388  if(mss * 7 < 64000u)
389  bufsize = mss * 7;
390  else if(mss * 6 < 64000u)
391  bufsize = mss * 6;
392  else
393  bufsize = mss * 5;
394 
395  Socket::sendsize(so, (unsigned)bufsize);
396  Socket::recvsize(so, (unsigned)bufsize);
397 
398  if(mss < 512)
399  Socket::sendwait(so, mss * 4);
400 
401 allocate:
403 }
404 
406 StreamBuffer()
407 {
408 }
409 
410 pipestream::pipestream(const char *cmd, access_t access, char **args, char **envp, size_t size) :
411 StreamBuffer()
412 {
413  open(cmd, access, args, envp, size);
414 }
415 
417 {
418  close();
419 }
420 
422 {
423  if(bufsize) {
425  close();
426  }
427 }
428 
430 {
431  if(gbuf)
432  fsys::release(rd);
433 
434  if(pbuf)
435  fsys::release(wr);
436 
438 }
439 
440 void pipestream::allocate(size_t size, access_t mode)
441 {
442  if(gbuf)
443  delete[] gbuf;
444 
445  if(pbuf)
446  delete[] pbuf;
447 
448  gbuf = pbuf = NULL;
449 
450  if(size < 2) {
451  bufsize = 1;
452  return;
453  }
454 
455  if(mode == RDONLY || mode == RDWR)
456  gbuf = new char[size];
457  if(mode == WRONLY || mode == RDWR)
458  pbuf = new char[size];
459  bufsize = size;
460  clear();
461  if(mode == RDONLY || mode == RDWR) {
462 #if (defined(__GNUC__) && (__GNUC__ < 3)) && !defined(MSWINDOWS) && !defined(STLPORT)
463  setb(gbuf, gbuf + size, 0);
464 #endif
465  setg(gbuf, gbuf + size, gbuf + size);
466  }
467  if(mode == WRONLY || mode == RDWR)
468  setp(pbuf, pbuf + size);
469 }
470 
472 {
473  ssize_t rlen = 1;
474  char ch;
475 
476  if(!gbuf)
477  return EOF;
478 
479  if(bufsize == 1) {
480  rlen = rd.read(&ch, 1);
481  if(rlen < 1) {
482  if(rlen < 0)
483  close();
484  return EOF;
485  }
486  return GET(ch);
487  }
488 
489  if(!gptr())
490  return EOF;
491 
492  if(gptr() < egptr())
493  return GET(*gptr());
494 
495  rlen = (ssize_t)((gbuf + bufsize) - eback());
496  rlen = rd.read(eback(), rlen);
497  if(rlen < 1) {
498 // clear(ios::failbit | rdstate());
499  if(rlen < 0)
500  close();
501  else
502  clear(ios::failbit | rdstate());
503  return EOF;
504  }
505 
506  setg(eback(), eback(), eback() + rlen);
507  return GET(*gptr());
508 }
509 
511 {
512  char ch;
513  ssize_t rlen, req;
514 
515  if(!pbuf)
516  return EOF;
517 
518  if(bufsize == 1) {
519  if(IS_EOF(c))
520  return EOF;
521 
522  ch = PUT(c);
523  rlen = wr.write(&ch, 1);
524  if(rlen < 1) {
525  if(rlen < 0)
526  close();
527  return EOF;
528  }
529  else
530  return c;
531  }
532 
533  if(!pbase())
534  return EOF;
535 
536  req = (ssize_t)(pptr() - pbase());
537  if(req) {
538  rlen = wr.write(pbase(), req);
539  if(rlen < 1) {
540  if(rlen < 0)
541  close();
542  return EOF;
543  }
544  req -= rlen;
545  }
546  // if write "partial", rebuffer remainder
547 
548  if(req)
549 // memmove(pbuf, pptr() + rlen, req);
550  memmove(pbuf, pbuf + rlen, req);
551  setp(pbuf, pbuf + bufsize);
552  pbump(req);
553 
554  if(c != EOF) {
555  *pptr() = PUT(c);
556  pbump(1);
557  }
558  return c;
559 }
560 
561 void pipestream::open(const char *path, access_t mode, char **args, char **envp, size_t size)
562 {
563 /*#ifdef RLIMIT_NOFILE
564  struct rlimit rlim;
565 
566  if(!getrlimit(RLIMIT_NOFILE, &rlim))
567  max = rlim.rlim_max;
568 #endif
569 */ close();
570 
573 
574  if(mode == RDONLY || mode == RDWR) {
575  if(fsys::pipe(input, stdio[1]))
576  return;
577  fsys::inherit(input, false);
578  }
579  else
580  stdio[1] = fsys::null();
581 
582  if(mode == WRONLY || mode == RDWR) {
583  if(fsys::pipe(stdio[0], output)) {
584  if(mode == RDWR) {
585  fsys::release(stdio[1]);
587  }
588  return;
589  }
590  }
591  else
592  stdio[0] = fsys::null();
593 
594  pid = shell::spawn(path, args, envp, stdio);
595 
596  fsys::release(stdio[0]);
597  fsys::release(stdio[1]);
598  if(pid == INVALID_PID_VALUE) {
602  }
603  else
604  allocate(size, mode);
605  rd.assign(input);
606  wr.assign(output);
607 }
608 
610 {
611  sync();
612 
613  if(bufsize) {
614  release();
615  return shell::wait(pid);
616  }
617  return -1;
618 }
619 
621 StreamBuffer()
622 {
623 }
624 
626 StreamBuffer()
627 {
628  if(copy.bufsize)
629  fd = copy.fd;
630  if(is(fd))
631  allocate(copy.bufsize, copy.ac);
632 }
633 
634 filestream::filestream(const char *filename, fsys::access_t mode, size_t size) :
635 StreamBuffer()
636 {
637  open(filename, mode, size);
638 }
639 
640 filestream::filestream(const char *filename, unsigned mode, fsys::access_t access, size_t size) :
641 StreamBuffer()
642 {
643  open(filename, mode, access, size);
644 }
645 
647 {
648  close();
649 }
650 
652 {
653  if(bufsize) {
654  sync();
655  fd.seek(offset);
656  }
657 }
658 
660 {
661  sync();
662  if(bufsize) {
663  fd.seek(0);
664  }
665 }
666 
668 {
669  sync();
670 
671  if(bufsize)
672  fd.close();
673 
675 }
676 
677 void filestream::allocate(size_t size, fsys::access_t mode)
678 {
679  if(gbuf)
680  delete[] gbuf;
681 
682  if(pbuf)
683  delete[] pbuf;
684 
685  gbuf = pbuf = NULL;
686  ac = mode;
687 
688  if(size < 2) {
689  bufsize = 1;
690  return;
691  }
692 
693  switch (mode) {
694  case fsys::RDONLY:
695  case fsys::RDWR:
696  case fsys::SHARED:
697  gbuf = new char[size];
698  default:
699  break;
700  }
701 
702  switch (mode) {
703  case fsys::WRONLY:
704  case fsys::APPEND:
705  case fsys::SHARED:
706  case fsys::RDWR:
707  pbuf = new char[size];
708  default:
709  break;
710  }
711 
712  bufsize = size;
713  clear();
714  switch (mode) {
715  case fsys::RDONLY:
716  case fsys::RDWR:
717  case fsys::SHARED:
718 #if (defined(__GNUC__) && (__GNUC__ < 3)) && !defined(MSWINDOWS) && !defined(STLPORT)
719  setb(gbuf, gbuf + size, 0);
720 #endif
721  setg(gbuf, gbuf + size, gbuf + size);
722  default:
723  break;
724  }
725 
726  switch (mode) {
727  case fsys::WRONLY:
728  case fsys::APPEND:
729  case fsys::SHARED:
730  case fsys::RDWR:
731  setp(pbuf, pbuf + size);
732  default:
733  break;
734  }
735 }
736 
737 void filestream::open(const char *fname, unsigned fmode, fsys::access_t access, size_t size)
738 {
739  close();
740  fd.open(fname, fmode, access);
741  if(is(fd))
742  allocate(size, access);
743 }
744 
745 void filestream::open(const char *fname, fsys::access_t access, size_t size)
746 {
747  close();
748  fd.open(fname, access);
749  if(is(fd))
750  allocate(size, access);
751 }
752 
754 {
755  ssize_t rlen = 1;
756 
757  if(!gbuf)
758  return EOF;
759 
760  if(!gptr())
761  return EOF;
762 
763  if(gptr() < egptr())
764  return GET(*gptr());
765 
766  rlen = (ssize_t)((gbuf + bufsize) - eback());
767  rlen = fd.read(eback(), rlen);
768  if(rlen < 1) {
769 // clear(ios::failbit | rdstate());
770  if(rlen < 0)
771  close();
772  else
773  clear(ios::failbit | rdstate());
774  return EOF;
775  }
776 
777  setg(eback(), eback(), eback() + rlen);
778  return GET(*gptr());
779 }
780 
782 {
783  ssize_t rlen, req;
784 
785  if(!pbuf)
786  return EOF;
787 
788  if(!pbase())
789  return EOF;
790 
791  req = (ssize_t)(pptr() - pbase());
792  if(req) {
793  rlen = fd.write(pbase(), req);
794  if(rlen < 1) {
795  if(rlen < 0)
796  close();
797  return EOF;
798  }
799  req -= rlen;
800  }
801  // if write "partial", rebuffer remainder
802 
803  if(req)
804 // memmove(pbuf, pptr() + rlen, req);
805  memmove(pbuf, pbuf + rlen, req);
806  setp(pbuf, pbuf + bufsize);
807  pbump(req);
808 
809  if(c != EOF) {
810  *pptr() = PUT(c);
811  pbump(1);
812  }
813  return c;
814 }
815 
816 omemstream::omemstream(char *mem, size_t size) :
817 std::streambuf(), std::ostream(this)
818 {
819  count = size;
820  pos = (uint8_t *)mem;
821  bp = (uint8_t *)mem;
822  zb = true;
823  *mem = 0;
824  --count;
825 }
826 
827 omemstream::omemstream(uint8_t *mem, size_t size) :
828 std::streambuf(), std::ostream(this)
829 {
830  count = size;
831  pos = mem;
832  bp = mem;
833  zb = false;
834 }
835 
837 {
838  if(ch == EOF)
839  return EOF;
840 
841  if(!count || !pos)
842  return EOF;
843 
844  --count;
845  *(pos++) = PUT(ch);
846  if(zb)
847  *(pos) = 0;
848  return ch;
849 }
850 
852 std::streambuf(), std::istream(this)
853 {
854  bp = (const uint8_t *)str;
855  count = strlen(str);
856  pos = (const uint8_t *)str;
857 }
858 
859 imemstream::imemstream(const uint8_t *str, size_t size) :
860 std::streambuf(), std::istream(this)
861 {
862  bp = str;
863  pos = str;
864  count = size;
865 }
866 
868 {
869  if(!count || !pos)
870  return EOF;
871  return GET(*pos);
872 }
873 
875 {
876  if(!count || !pos)
877  return EOF;
878  --count;
879  return GET(*(pos++));
880 }
881 
882 bool getline(std::istream& in, char *buffer, size_t size)
883 {
884  *buffer = 0;
885  if(!in.good())
886  return false;
887 
888  in.getline(buffer, size);
889  if(!buffer[0])
890  return false;
891 
892  return true;
893 }
894 
895 bool putline(std::ostream& out, char *buffer)
896 {
897  if(!out.good())
898  return false;
899 
900  out << buffer << std::endl;
901  return out.good();
902 }
903 
904 std::istream& _stream_operators::input(std::istream& inp, InputProtocol& fmt)
905 {
906  int c = 0;
907  while(!c) {
908  if(!inp.good())
909  c = EOF;
910  else
911  c = inp.get();
912 
913  c = fmt._input(c);
914  if(!c)
915  continue;
916  if(c != EOF)
917  inp.putback(c);
918  }
919  return inp;
920 }
921 
922 std::ostream& _stream_operators::print(std::ostream& out, const PrintProtocol& fmt)
923 {
924  if(out.good()) {
925  const char *cp = fmt._print();
926 
927  if(cp)
928  out.write(cp, strlen(cp));
929  else
930  out << std::endl;
931  }
932  return out;
933 }
934 
935 std::istream& _stream_operators::input(std::istream& inp, string_t& str)
936 {
937  inp.getline(str.data(), str.size());
938  return inp;
939 }
940 
941 std::ostream& _stream_operators::print(std::ostream& out, const string_t& str)
942 {
943  out.write(str.c_str(), str.len());
944  return out;
945 }
946 
947 std::istream& _stream_operators::input(std::istream& inp, stringlist_t& list)
948 {
949  size_t size = list.size() - 64;
950 
951  char *tmp = (char *)malloc(size);
952  while(inp.good()) {
953  inp.getline(tmp, size);
954  if(!list.filter(tmp, size))
955  break;
956  }
957  free(tmp);
958  return inp;
959 }
960 
961 std::ostream& _stream_operators::print(std::ostream& out, const stringlist_t& list)
962 {
963  StringPager::iterator sp = list.begin();
964  while(is(sp) && out.good()) {
965  const char *cp = sp->get();
966  size_t size = strlen(cp);
967  if(size)
968  out.write(cp, size);
969  out.put('\n');
970  sp.next();
971  }
972  return out;
973 }
974 
975 std::string& _stream_operators::append(std::string& target, String& source)
976 {
977  size_t size = source.count();
978  if(!size)
979  return target;
980 
981  const char *buf = source.c_str();
982  std::string tmp(buf, size);
983  target += tmp;
984  return target;
985 }
986 
987 class __LOCAL NullBuffer : public std::streambuf
988 {
989 private:
991 
992  NullBuffer();
993 
994 public:
995  int overflow(int c) __OVERRIDE;
996 
997  int underflow() __OVERRIDE;
998 
999  int uflow() __OVERRIDE;
1000 
1001  static NullBuffer null;
1002 };
1003 
1004 NullBuffer::NullBuffer() : streambuf()
1005 {
1006 }
1007 
1009 {
1010  return c;
1011 }
1012 
1014 {
1015  return EOF;
1016 }
1017 
1019 {
1020  return EOF;
1021 }
1022 
1024 
1025 static std::iostream nullstream(&NullBuffer::null);
1026 
1027 } // namespace ucommon
1028 
1029 namespace std {
1030  using namespace ucommon;
1031  iostream& null = nullstream;
1032 }
1033 
1034 #endif
1035 
ucommon::fsys::APPEND
Definition: fsys.h:165
ucommon::imemstream::pos
const uint8_t * pos
Definition: stream.h:462
ucommon::StreamBuffer::gbuf
char * gbuf
Definition: stream.h:71
ucommon::filestream::ac
fsys::access_t ac
Definition: stream.h:361
ucommon::String::len
size_t len(void) const
Definition: string.cpp:145
ucommon::StreamBuffer::StreamBuffer
StreamBuffer()
Definition: stream.cpp:56
ucommon::StringPager::begin
StringPager::member * begin(void) const
Definition: memory.h:547
ucommon::fsys::write
ssize_t write(const void *buffer, size_t count)
Definition: fsys.cpp:769
ucommon::Socket::sendwait
int sendwait(unsigned size)
Definition: socket.h:1053
ucommon::tcpstream::underflow
int underflow(void) __OVERRIDE
Definition: stream.cpp:193
ucommon::shell::spawn
static shell::pid_t spawn(const char *path, char **argv, char **env=NULL, fd_t *stdio=NULL)
Definition: shell.cpp:2012
export.h
ucommon::StreamBuffer::pbuf
char * pbuf
Definition: stream.h:71
ucommon::PrintProtocol
Definition: protocols.h:134
ucommon::fsys::access_t
access_t
Definition: fsys.h:160
ucommon::InputProtocol
Definition: protocols.h:153
fd_t
int fd_t
Definition: platform.h:415
ucommon::StreamBuffer::allocate
void allocate(size_t size)
Definition: stream.cpp:76
ucommon::Socket::disconnect
int disconnect(void)
Definition: socket.cpp:2508
out
static shell::stringopt out('o', "--output", _TEXT("output file"), "filename", "-")
ucommon::imemstream::underflow
int underflow() __OVERRIDE
Definition: stream.cpp:867
ucommon::NullBuffer::null
static NullBuffer null
Definition: stream.cpp:1001
ucommon::fsys::read
ssize_t read(void *buffer, size_t count)
Definition: fsys.cpp:750
ucommon::filestream::close
void close(void)
Definition: stream.cpp:667
ucommon::filestream::seek
void seek(fsys::offset_t offset)
Definition: stream.cpp:651
ucommon
Definition: access.cpp:23
ucommon::InputProtocol::_input
virtual int _input(int code)=0
ucommon::pipestream::WRONLY
Definition: stream.h:242
ucommon::tcpstream::tcpstream
tcpstream(const tcpstream &copy)
Definition: stream.cpp:126
ucommon::omemstream::zb
bool zb
Definition: stream.h:499
ucommon::omemstream::count
size_t count
Definition: stream.h:497
__LOCAL
#define __LOCAL
Definition: platform.h:298
ucommon::tcpstream::close
void close(void)
Definition: stream.cpp:334
ucommon::Socket::sendsize
int sendsize(unsigned size)
Definition: socket.h:1044
__OVERRIDE
#define __OVERRIDE
Definition: platform.h:158
INVALID_HANDLE_VALUE
#define INVALID_HANDLE_VALUE
Definition: platform.h:417
ucommon::String
Definition: string.h:78
timeout_t
unsigned long timeout_t
Definition: platform.h:453
ucommon::_stream_operators::print
static std::ostream & print(std::ostream &out, const PrintProtocol &format)
Definition: stream.cpp:922
ucommon::filestream::~filestream
virtual ~filestream()
Definition: stream.cpp:646
ucommon::Socket::recvfrom
static ssize_t recvfrom(socket_t socket, void *buffer, size_t size, int flags=0, struct sockaddr_storage *address=NULL)
Definition: socket.cpp:1890
ucommon::tcpstream::release
void release(void)
Definition: stream.cpp:165
ucommon::filestream
Definition: stream.h:347
ucommon::StringPager
Definition: memory.h:401
ucommon::copy
T copy(const T &src)
Definition: generics.h:395
ucommon::pipestream::RDWR
Definition: stream.h:243
ucommon::filestream::underflow
int underflow(void) __OVERRIDE
Definition: stream.cpp:753
ucommon::NullBuffer::NullBuffer
NullBuffer()
Definition: stream.cpp:1004
ucommon::fsys::offset_t
long offset_t
Definition: fsys.h:176
ucommon::StreamBuffer::release
void release(void)
Definition: stream.cpp:103
ucommon::getline
bool getline(std::istream &in, char *buffer, size_t size)
Definition: stream.cpp:882
MSG_WAITALL
#define MSG_WAITALL
Definition: stream.cpp:172
ucommon::pipestream::underflow
int underflow(void) __OVERRIDE
Definition: stream.cpp:471
ucommon::StringPager::filter
virtual bool filter(char *text, size_t size)
Definition: memory.cpp:509
ucommon::filestream::filestream
filestream()
Definition: stream.cpp:620
ucommon::Socket::connectto
int connectto(struct addrinfo *list)
Definition: socket.cpp:2503
ucommon::clear
T & clear(T &o)
Definition: generics.h:416
ucommon::Socket::sendto
static ssize_t sendto(socket_t socket, const void *buffer, size_t size, int flags=0, const struct sockaddr *address=NULL)
Definition: socket.cpp:1936
output
static FILE * output
Definition: car.cpp:43
ucommon::NullBuffer::uflow
int uflow() __OVERRIDE
Definition: stream.cpp:1018
ucommon::pipestream::RDONLY
Definition: stream.h:241
ucommon::tcpstream::~tcpstream
virtual ~tcpstream()
Definition: stream.cpp:160
ucommon::omemstream::pos
uint8_t * pos
Definition: stream.h:498
ucommon::max
T &() max(T &o1, T &o2)
Definition: generics.h:445
ucommon::StreamBuffer
Definition: stream.h:64
ucommon::tcpstream::reset
__LOCAL void reset(void)
Definition: stream.cpp:317
ucommon::filestream::fd
fsys_t fd
Definition: stream.h:360
ucommon::tcpstream::overflow
int overflow(int ch) __OVERRIDE
Definition: stream.cpp:240
ucommon::ListenSocket::accept
socket_t accept(struct sockaddr_storage *address=NULL) const
Definition: socket.cpp:2809
ucommon::String::size
size_t size(void) const
Definition: string.cpp:137
ucommon::omemstream::omemstream
omemstream(uint8_t *data, size_t size)
Definition: stream.cpp:827
ucommon::fsys::SHARED
Definition: fsys.h:166
ucommon::fsys::RDWR
Definition: fsys.h:164
ucommon::pipestream::pipestream
pipestream()
Definition: stream.cpp:405
ucommon::fsys::close
int close(void)
Definition: fsys.cpp:820
thread.h
ucommon::String::data
int int size_t size_t char * data(void)
Definition: string.cpp:281
ucommon::Socket::create
static socket_t create(int family, int type, int protocol)
Definition: socket.cpp:1731
ucommon::tcpstream::allocate
__LOCAL void allocate(unsigned size)
Definition: stream.cpp:353
ucommon::filestream::rewind
void rewind(void)
Definition: stream.cpp:659
ucommon::NullBuffer::overflow
int overflow(int c) __OVERRIDE
Definition: stream.cpp:1008
input
static shell::stringopt input('i', "--input", _TEXT("stdin path to use"), "filename")
ucommon::NullBuffer
Definition: stream.cpp:987
ucommon::TCPServer
Definition: socket.h:1900
ucommon::fsys::inherit
static int inherit(fd_t &descriptor, bool enable)
Definition: fsys.cpp:1073
stream.h
ucommon::fsys::release
fd_t release(void)
Definition: fsys.cpp:1775
ucommon::StreamBuffer::bufsize
size_t bufsize
Definition: stream.h:70
ucommon::fsys::null
static fd_t null(void)
Definition: fsys.cpp:778
ucommon::omemstream::overflow
int overflow(int ch) __OVERRIDE
Definition: stream.cpp:836
ucommon::pipestream::wr
fsys_t wr
Definition: stream.h:252
ch
#define ch(x, y, z)
Definition: sha2.cpp:120
ucommon::NullBuffer::underflow
int underflow() __OVERRIDE
Definition: stream.cpp:1013
ucommon::shell::cancel
static int cancel(shell::pid_t pid)
Definition: shell.cpp:2083
ucommon::linked_pointer
Definition: linked.h:991
ucommon::fsys::assign
void assign(fd_t descriptor)
Definition: fsys.h:491
INVALID_SOCKET
#define INVALID_SOCKET
Definition: platform.h:416
ucommon::StreamBuffer::uflow
int uflow() __OVERRIDE
Definition: stream.cpp:63
ucommon::pipestream::overflow
int overflow(int ch) __OVERRIDE
Definition: stream.cpp:510
ucommon::pipestream::pid
shell::pid_t pid
Definition: stream.h:253
__DELETE_COPY
#define __DELETE_COPY(x)
Definition: platform.h:160
ucommon::Socket::release
void release(void)
Definition: socket.cpp:1764
ucommon::omemstream::mem
uint8_t * mem() const
Definition: stream.h:511
ucommon::tcpstream::_read
virtual ssize_t _read(char *buffer, size_t size)
Definition: stream.cpp:183
ucommon::tcpstream::_write
virtual ssize_t _write(const char *buffer, size_t size)
Definition: stream.cpp:188
ucommon::StreamBuffer::sync
int sync(void)
Definition: stream.cpp:116
ucommon::str
String str(Socket &so, size_t size)
Definition: socket.cpp:3507
ucommon::pipestream::close
int close(void)
Definition: stream.cpp:609
ucommon::linked_pointer::next
void next(void)
Definition: linked.h:1106
buffer
static uint8_t buffer[65536]
Definition: zerofill.cpp:27
ucommon::pipestream::allocate
__LOCAL void allocate(size_t size, access_t mode)
Definition: stream.cpp:440
ucommon::imemstream::bp
const uint8_t * bp
Definition: stream.h:462
ucommon::_stream_operators::append
static std::string & append(std::string &target, String &source)
Definition: stream.cpp:975
ucommon::pipestream::release
void release(void)
Definition: stream.cpp:429
ucommon::Socket::family
static int family(socket_t socket)
Definition: socket.cpp:3428
IS_EOF
#define IS_EOF(x)
Definition: stream.cpp:52
ucommon::Socket::address
Definition: socket.h:364
ucommon::tcpstream::so
socket_t so
Definition: stream.h:121
GET
#define GET(x)
Definition: stream.cpp:53
ucommon::pipestream::rd
fsys_t rd
Definition: stream.h:252
ucommon::omemstream::bp
uint8_t * bp
Definition: stream.h:498
ucommon::fsys::open
void open(const char *path, access_t access)
Definition: fsys.cpp:919
string.h
ucommon::filestream::allocate
__LOCAL void allocate(size_t size, fsys::access_t mode)
Definition: stream.cpp:677
ucommon::Socket::recvsize
int recvsize(unsigned size)
Definition: socket.h:1062
ucommon::pipestream::terminate
void terminate(void)
Definition: stream.cpp:421
ucommon::putline
bool putline(std::ostream &out, char *buffer)
Definition: stream.cpp:895
ucommon::String::c_str
const char * c_str(void) const
Definition: string.cpp:289
ucommon::tcpstream::_wait
virtual bool _wait(void)
Definition: stream.cpp:175
ucommon::Socket::address::family
int family(void) const
Definition: socket.cpp:1136
ucommon::Socket::wait
bool wait(timeout_t timeout=0) const
Definition: socket.cpp:2665
ucommon::tcpstream::open
void open(Socket::address &address, unsigned segment=536)
Definition: stream.cpp:288
ucommon::PrintProtocol::_print
virtual const char * _print(void) const =0
socket.h
ucommon::StringPager::size
size_t size(void) const
Definition: memory.h:626
ucommon::fsys::RDONLY
Definition: fsys.h:161
ucommon::imemstream::count
size_t count
Definition: stream.h:461
ucommon::fsys::pipe
static int pipe(fd_t &input, fd_t &output, size_t size=0)
Definition: fsys.cpp:783
ucommon::imemstream::uflow
int uflow() __OVERRIDE
Definition: stream.cpp:874
ucommon::filestream::open
void open(const char *filename, fsys::access_t access, size_t buffering=512)
Definition: stream.cpp:745
ucommon::pipestream::access_t
access_t
Definition: stream.h:240
shell.h
ucommon::imemstream::imemstream
imemstream(const uint8_t *data, size_t size)
Definition: stream.cpp:859
ucommon::_stream_operators::input
static std::istream & input(std::istream &inp, InputProtocol &format)
Definition: stream.cpp:904
ucommon::fsys::WRONLY
Definition: fsys.h:162
ucommon::Socket::query
static struct addrinfo * query(const char *host, const char *service, int type=SOCK_STREAM, int protocol=0)
Definition: socket.cpp:956
ucommon::filestream::overflow
int overflow(int ch) __OVERRIDE
Definition: stream.cpp:781
ucommon::tcpstream
Definition: stream.h:114
ucommon::String::count
size_t count(void) const
Definition: string.cpp:618
ucommon::pipestream::open
void open(const char *path, access_t access, char **args, char **env=NULL, size_t buffering=512)
Definition: stream.cpp:561
addrinfo
Definition: socket.cpp:83
PUT
#define PUT(x)
Definition: stream.cpp:54
ucommon::fsys::seek
int seek(offset_t offset)
Definition: fsys.cpp:1124
ucommon::pipestream::~pipestream
virtual ~pipestream()
Definition: stream.cpp:416
ucommon::shell::wait
static int wait(shell::pid_t pid)
Definition: shell.cpp:2070
ucommon::is
bool is(T &object)
Definition: generics.h:292
ucommon::tcpstream::timeout
timeout_t timeout
Definition: stream.h:122
EOF
#define EOF
Definition: stream.cpp:51
INVALID_PID_VALUE
#define INVALID_PID_VALUE
Definition: shell.h:43