Changeset c3ee5f3 for benchmark/io/http/protocol.cfa
- Timestamp:
- Jan 8, 2021, 5:20:16 PM (3 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 35fd2c4
- Parents:
- 390fb02
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/io/http/protocol.cfa
r390fb02 rc3ee5f3 18 18 #include "options.hfa" 19 19 20 const char * volatile date = "Wed, 17 Apr 2013 12:00:00 GMT";20 const char * volatile date = 0p; 21 21 22 22 const char * http_msgs[] = { … … 78 78 for() { 79 79 int ret = cfa_read(fd, (void*)it, count, 0, -1`s, 0p, 0p); 80 // int ret = read(fd, (void*)it, count); 80 81 if(ret == 0 ) return [OK200, true, 0, 0]; 81 82 if(ret < 0 ) { 82 83 if( errno == EAGAIN || errno == EWOULDBLOCK) continue READ; 84 // if( errno == EINVAL ) return [E400, true, 0, 0]; 83 85 abort( "read error: (%d) %s\n", (int)errno, strerror(errno) ); 84 86 } … … 129 131 } 130 132 } 133 134 //============================================================================================= 135 136 #include <clock.hfa> 137 #include <time.hfa> 138 #include <thread.hfa> 139 140 struct date_buffer { 141 char buff[100]; 142 }; 143 144 thread DateFormater { 145 int idx; 146 date_buffer buffers[2]; 147 }; 148 149 void ?{}( DateFormater & this ) { 150 ((thread&)this){ *options.clopts.instance }; 151 this.idx = 0; 152 memset( this.buffers[0].buff, 0, sizeof(this.buffers[0]) ); 153 memset( this.buffers[1].buff, 0, sizeof(this.buffers[1]) ); 154 } 155 156 void main(DateFormater & this) { 157 LOOP: for() { 158 waitfor( ^?{} : this) { 159 break LOOP; 160 } 161 or else {} 162 163 Time now = getTimeNsec(); 164 // Date: Wed, 17 Apr 2013 12:00:00 GMT 165 strftime( this.buffers[this.idx].buff, 100, "%a, %d %b %Y %H:%M:%S %Z", now ); 166 printf("Changing date to %s\n", this.buffers[this.idx].buff); 167 168 char * next = this.buffers[this.idx].buff; 169 __atomic_exchange_n((char * volatile *)&date, next, __ATOMIC_SEQ_CST); 170 this.idx = (this.idx + 1) % 2; 171 172 sleep(1`s); 173 } 174 } 175 176 //============================================================================================= 177 DateFormater * the_date_formatter; 178 179 void init_protocol(void) { 180 the_date_formatter = alloc(); 181 (*the_date_formatter){}; 182 } 183 184 void deinit_protocol(void) { 185 ^(*the_date_formatter){}; 186 free( the_date_formatter ); 187 }
Note: See TracChangeset
for help on using the changeset viewer.