Add a http performance test script based on wrk
[iec.git] / src / type3_AndroidCloud / anbox-master / external / android-emugl / host / include / libOpenglRender / IOStream.h
1 /*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #ifndef __IO_STREAM_H__
17 #define __IO_STREAM_H__
18
19 #include <stdlib.h>
20 #include <stdio.h>
21
22 class IOStream {
23 public:
24     IOStream(size_t bufSize) {
25         m_buf = NULL;
26         m_bufsize = bufSize;
27         m_free = 0;
28     }
29
30     virtual void *allocBuffer(size_t minSize) = 0;
31     virtual size_t commitBuffer(size_t size) = 0;
32     virtual const unsigned char *read(void *buf, size_t *inout_len) = 0;
33     virtual void forceStop() = 0;
34
35     virtual ~IOStream() {
36         // NOTE: m_buf is 'owned' by the child class thus we expect it to be released by it
37     }
38
39     unsigned char *alloc(size_t len) {
40         if (m_buf && len > m_free) {
41             if (flush() < 0)
42                 return NULL; // we failed to flush so something is wrong
43         }
44
45         if (!m_buf || len > m_bufsize) {
46             int allocLen = m_bufsize < len ? len : m_bufsize;
47             m_buf = static_cast<unsigned char *>(allocBuffer(allocLen));
48             if (!m_buf)
49                 return NULL;
50             m_bufsize = m_free = allocLen;
51         }
52
53         unsigned char *ptr;
54
55         ptr = m_buf + (m_bufsize - m_free);
56         m_free -= len;
57
58         return ptr;
59     }
60
61     int flush() {
62         if (!m_buf || m_free == m_bufsize) return 0;
63
64         int stat = commitBuffer(m_bufsize - m_free);
65         m_buf = NULL;
66         m_free = 0;
67         return stat;
68     }
69
70 private:
71     unsigned char *m_buf;
72     size_t m_bufsize;
73     size_t m_free;
74 };
75
76 //
77 // When a client opens a connection to the renderer, it should
78 // send unsigned int value indicating the "clientFlags".
79 // The following are the bitmask of the clientFlags.
80 // currently only one bit is used which flags the server
81 // it should exit.
82 //
83 #define IOSTREAM_CLIENT_EXIT_SERVER      1
84
85 #endif