src/sock_test.c
changeset 46 0c13bca53ae1
parent 43 42f5dc680930
child 118 05b8d5150313
equal deleted inserted replaced
45:71e65564afd2 46:0c13bca53ae1
   204     // set EOF flag?
   204     // set EOF flag?
   205     if (eof)
   205     if (eof)
   206         sock->eof = true;
   206         sock->eof = true;
   207 }
   207 }
   208 
   208 
       
   209 void sock_test_notify_events (struct sock_test *sock)
       
   210 {
       
   211     // notify if events are enabled
       
   212     if (sock->ev_mask) {
       
   213         // zero mask
       
   214         int mask = sock->ev_mask;
       
   215         sock->ev_mask = 0;
       
   216 
       
   217         sock_stream_invoke_callbacks(SOCK_TEST_BASE(sock), mask);
       
   218     }
       
   219 }
       
   220 
   209 void sock_test_add_recv_vec (struct sock_test *sock, struct io_vec new_vec)
   221 void sock_test_add_recv_vec (struct sock_test *sock, struct io_vec new_vec)
   210 {
   222 {
   211     struct io_buf *buf = &sock->recv_buf;
   223     struct io_buf *buf = &sock->recv_buf;
   212 
   224 
   213     // ensure there's room
   225     // ensure there's room
   214     assert(sock_test_grow_buf(buf) == SUCCESS);
   226     assert(sock_test_grow_buf(buf) == SUCCESS);
   215     
   227     
   216     // copy    
   228     // copy    
   217     *(buf->write_vec++) = new_vec;
   229     *(buf->write_vec++) = new_vec;
   218 
   230     
   219     // notify events?
   231     // notify
   220     if (sock->ev_mask) {
   232     sock_test_notify_events(sock);
   221         int mask = sock->ev_mask;
       
   222         sock->ev_mask = 0;
       
   223 
       
   224         sock_stream_invoke_callbacks(SOCK_TEST_BASE(sock), mask);
       
   225     }
       
   226 }
   233 }
   227 
   234 
   228 void sock_test_add_recv_str (struct sock_test *sock, const char *str)
   235 void sock_test_add_recv_str (struct sock_test *sock, const char *str)
   229 {
   236 {
   230     struct io_vec vec = {
   237     struct io_vec vec = {
   231         (char*) str, strlen(str)
   238         (char*) str, strlen(str)
   232     };
   239     };
   233 
   240 
   234     sock_test_add_recv_vec(sock, vec);
   241     sock_test_add_recv_vec(sock, vec);
       
   242 }
       
   243 
       
   244 void sock_test_set_recv_eof (struct sock_test *sock)
       
   245 {
       
   246     sock->eof = true;
       
   247 
       
   248     sock_test_notify_events(sock);
   235 }
   249 }
   236 
   250 
   237 void sock_test_get_send_data (struct sock_test *sock, char **buf_ptr, size_t *len_ptr)
   251 void sock_test_get_send_data (struct sock_test *sock, char **buf_ptr, size_t *len_ptr)
   238 {
   252 {
   239     struct io_buf *buf = &sock->send_buf;
   253     struct io_buf *buf = &sock->send_buf;