17 #include <libubox/ustream.h>
23 static struct blob_buf
b;
36 static int counter = 0;
38 struct timeval tv1, tv2;
44 blobmsg_add_u32(&
b,
"counter", counter++);
46 gettimeofday(&tv1, NULL);
47 for (i = 0; i < max; i++)
49 gettimeofday(&tv2, NULL);
53 delta = (tv2.tv_sec - tv1.tv_sec) * 1000000 + (tv2.tv_usec - tv1.tv_usec);
54 fprintf(stderr,
"Avg time per iteration: %ld usec\n", delta / max);
56 uloop_timeout_set(
timeout, 1000);
65 [
RETURN_CODE] = { .name =
"rc", .type = BLOBMSG_TYPE_INT32 },
69 int type,
struct blob_attr *msg)
73 uint32_t count_to = *(uint32_t *)req->
priv;
78 fprintf(stderr,
"No return code received from server\n");
83 fprintf(stderr,
"Corruption of data with count up to '%u'\n", count_to);
85 fprintf(stderr,
"Server validated our count up to '%u'\n", count_to);
92 COUNT_TO_MAX = 1000000,
97 static uint32_t count_to = 100000;
98 static int count_progression = PROGRESSION;
101 if (count_to <= COUNT_TO_MIN)
102 count_progression = PROGRESSION;
103 else if (count_to >= COUNT_TO_MAX)
104 count_progression = -PROGRESSION;
106 count_to += count_progression;
110 fprintf(stderr,
"Could not allocate memory to count up to '%u'\n", count_to);
114 fprintf(stderr,
"Sending count up to '%u'; string has length '%u'\n",
115 count_to, (uint32_t)strlen(s));
116 blob_buf_init(&
b, 0);
117 blobmsg_add_u32(&
b,
"to", count_to);
118 blobmsg_add_string(&
b,
"string", s);
122 fprintf(stderr,
"Failed to look up test object\n");
130 uloop_timeout_set(
timeout, 2000);
146 data = ustream_get_read_buf(s, &len);
150 sep = strchr(data,
'\n');
155 fprintf(stderr,
"Got line: %s\n", data);
156 ustream_consume(s, sep + 1 - data);
161 static struct ustream_fd test_fd;
163 fprintf(stderr,
"Got fd from the server, watching...\n");
166 ustream_fd_init(&test_fd, fd);
171 fprintf(stderr,
"completed request, ret: %d\n", ret);
182 fprintf(stderr,
"Failed to add_object object: %s\n",
ubus_strerror(ret));
187 fprintf(stderr,
"Failed to look up test object\n");
191 blob_buf_init(&
b, 0);
196 blob_buf_init(&
b, 0);
197 blobmsg_add_string(&
b,
"msg",
"blah");
208 int main(
int argc,
char **argv)
210 const char *ubus_socket = NULL;
213 while ((ch = getopt(argc, argv,
"cs:")) != -1) {
216 ubus_socket = optarg;
227 fprintf(stderr,
"Failed to connect to ubus\n");
static void client_main(void)
static void test_client_subscribe_cb(struct ubus_context *ctx, struct ubus_object *obj)
static void test_client_fd_data_cb(struct ustream *s, int bytes)
static struct uloop_timeout notify_timer
static const struct blobmsg_policy return_policy[__RETURN_MAX]
static void test_count_data_cb(struct ubus_request *req, int type, struct blob_attr *msg)
int main(int argc, char **argv)
static struct ubus_context * ctx
static void test_client_fd_cb(struct ubus_request *req, int fd)
static void test_client_notify_cb(struct uloop_timeout *timeout)
static void test_count(struct uloop_timeout *timeout)
static void test_client_complete_cb(struct ubus_request *req, int ret)
static struct uloop_timeout count_timer
static struct ubus_object test_client_object
char * count_to_number(uint32_t num)
int ubus_add_object(struct ubus_context *ctx, struct ubus_object *obj)
int ubus_notify(struct ubus_context *ctx, struct ubus_object *obj, const char *type, struct blob_attr *msg, int timeout)
void ubus_complete_request_async(struct ubus_context *ctx, struct ubus_request *req)
struct ubus_context * ubus_connect(const char *path)
void ubus_free(struct ubus_context *ctx)
int ubus_lookup_id(struct ubus_context *ctx, const char *path, uint32_t *id)
const char * ubus_strerror(int error)
static void ubus_add_uloop(struct ubus_context *ctx)
static int ubus_invoke_async(struct ubus_context *ctx, uint32_t obj, const char *method, struct blob_attr *msg, struct ubus_request *req)
static int ubus_invoke(struct ubus_context *ctx, uint32_t obj, const char *method, struct blob_attr *msg, ubus_data_handler_t cb, void *priv, int timeout)
ubus_state_handler_t subscribe_cb
ubus_complete_handler_t complete_cb