int x = 0;
if (zap_channel_command(chan, ZAP_COMMAND_SET_INTERVAL, &ms) == ZAP_SUCCESS) {
- zap_channel_command(chan, ZAP_COMMAND_SET_INTERVAL, &ms);
+ ms = 0;
+ zap_channel_command(chan, ZAP_COMMAND_GET_INTERVAL, &ms);
printf("interval set to %u\n", ms);
} else {
- printf("set interval failed\n");
+ printf("set interval failed [%s]\n", chan->last_error);
}
for(x = 0; x < 25; x++) {
- unsigned char buf[80];
+ unsigned char buf[2048];
zap_size_t len = sizeof(buf);
zap_wait_flag_t flags = ZAP_READ;
-
- zap_channel_wait(chan, &flags, 0);
+
+ if (zap_channel_wait(chan, &flags, 0) == ZAP_FAIL) {
+ printf("wait FAIL! %d [%s]\n", len, chan->last_error);
+ }
if (flags & ZAP_READ) {
if (zap_channel_read(chan, buf, &len) == ZAP_SUCCESS) {
printf("READ: %d\n", len);
} else {
- printf("READ FAIL! %d\n", len);
+ printf("READ FAIL! %d [%s]\n", len, chan->last_error);
break;
}
} else {
- printf("wait fail\n");
+ printf("wait fail [%s]\n", chan->last_error);
}
}
}
return configured;
}
-static zap_status_t wp_tdm_cmd_exec(zap_socket_t fd, wanpipe_tdm_api_t *tdm_api)
+static zap_status_t wp_tdm_cmd_exec(zap_channel_t *zchan, wanpipe_tdm_api_t *tdm_api)
{
int err;
#if defined(WIN32)
- err = tdmv_api_ioctl(fd, &tdm_api->wp_tdm_cmd);
+ err = tdmv_api_ioctl(zchan->sockfd, &tdm_api->wp_tdm_cmd);
#else
- err = ioctl(fd,SIOC_WANPIPE_TDM_API,&tdm_api->wp_tdm_cmd);
+ err = ioctl(zchan->sockfd, SIOC_WANPIPE_TDM_API, &tdm_api->wp_tdm_cmd);
#endif
- return err ? ZAP_FAIL : ZAP_SUCCESS;
+
+ if (err) {
+ snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno));
+ return ZAP_FAIL;
+ }
+
+ return ZAP_SUCCESS;
}
static ZINT_CONFIGURE_FUNCTION(wanpipe_configure)
{
tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_USR_PERIOD;
- if (!(err = wp_tdm_cmd_exec(zchan->sockfd, &tdm_api))) {
+ if (!(err = wp_tdm_cmd_exec(zchan, &tdm_api))) {
*((int *)obj) = tdm_api.wp_tdm_cmd.usr_period;
}
{
tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD;
tdm_api.wp_tdm_cmd.usr_period = *((int *)obj);
- err = wp_tdm_cmd_exec(zchan->sockfd, &tdm_api);
+ err = wp_tdm_cmd_exec(zchan, &tdm_api);
}
break;
};
- return err ? ZAP_FAIL : ZAP_SUCCESS;
+ if (err) {
+ snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno));
+ return ZAP_FAIL;
+ }
+
+
+ return ZAP_SUCCESS;
}
static ZINT_WAIT_FUNCTION(wanpipe_wait)
s = select(zchan->sockfd + 1, r, w, e, tvp);
if (s < 0) {
+ snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno));
return ZAP_FAIL;
}
*datalen = rx_len;
if (rx_len <= 0) {
- perror("wtf");
+ snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", strerror(errno));
return ZAP_FAIL;
}
bsent -= sizeof(wp_tdm_api_tx_hdr_t);
}
+ *datalen = bsent;
}
#endif