--- /dev/null
+CFLAGS+= -Wall -Wextra
#include <sys/un.h>
#include <unistd.h>
+#include <stdio.h>
#include "fwp_conf.h"
#include "fwp_msgb.h"
#include "fwp_ac.h"
#include "fwp_util.h"
-
enum ac_status_t {
FWP_AC_CLOSED = 0,
FWP_AC_OPENED = 1
int fwp_ac_open(unsigned int id)
{
int sockfd;
- unsigned int yes=1, tos;
+ unsigned int tos;
struct fwp_ac *ac = &fwp_ac_table[id];
//if ((id < 0)||(id >= AC_NUM)||(ac[id].status != OPENED))
return 0;
}
- if ((sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0)
- {
- /*perror("Unable to open socket");*/
- return -1;
+ if ((sockfd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
+ perror("fwp_ac_open - Unable to open socket for AC");
+ return (-errno);
}
- if (setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int)) == -1) {
- /*perror("Unable to set socket");*/
- return -1;
- }
+ /*
+ * Not needed
+ * unisgned int yes = 1;
+ * if (setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR, &yes,
+ * sizeof(int)) == -1) {
+ * perror("fwp_ac_open - Root permission needed to set AC)");
+ close(sockfd);
+ return (-errno);
+ }*/
tos = ac_to_tos[id];
- if (setsockopt(sockfd, SOL_IP, IP_TOS, &tos, sizeof(tos))) {
- /*perror("Unable to set TOS");*/
+#if 0
+ if (setsockopt(sockfd, SOL_IP, IP_TOS, &tos, sizeof(tos)) == -1) {
+ perror("fwp_ac_open - Root permission needed to set AC");
close(sockfd);
- return -1;
+ return (-errno);
}
-
+#endif
ac->sockfd = sockfd;
ac->status = FWP_AC_OPENED;
ac->count++;
-
return 0;
}
-
int fwp_ac_close(unsigned int id)
{
struct fwp_ac *ac = &fwp_ac_table[id];
- if (ac->status != FWP_AC_OPENED) return -1;
+ if (ac->status != FWP_AC_OPENED)
+ return -EPERM;
if (--ac->count == 0) {
close(ac->sockfd);
ac->status = FWP_AC_CLOSED;
}
+
return 0;
}
int fwp_ac_send(unsigned int id, struct fwp_msgb* msgb)
{
+ if (!msgb)
+ return -EINVAL;
while (sendto(fwp_ac_table[id].sockfd, msgb->head, msgb->len,
/*msgb_>flags*/0, &msgb->addr, msgb->addrlen) < 0) {
if (errno == EINTR) continue;
- /*perror("Error while sending data");*/
- return -1;
+ perror("fwp_ac_send - Error while sending data");
+ return (-errno);
}
return 0;
}
-
{
fwp_vres_table_init();
fwp_ac_table_init();
-
+
+#if 0
/* Open socket to fwp agent */
#warning Asi to bude chtit pouzit SOCK_DGRAM nebo SOCK_SEQPACKET, abychom nemuseli hledat zacatky paketu.
strcpy(fwp_agent_addr.sun_path, "manager_socket");
#warning Chybi volani bind() a v pripade SOCK_STREAM connect()
+#endif
return 0;
}
static void* fwp_vres_tx_thread(void *_vres);
enum fwp_vres_status_t {
- CLOSED = 0 ,
- OPENED = 1 ,
+ FWP_VRES_CLOSED = 0 ,
+ FWP_VRES_OPENED = 1 ,
};
/**
struct fwp_msgq tx_queue;
pthread_t tx_thread;
pthread_attr_t tx_thread_attr;
- unsigned int status;
+ int status;
};
struct fwp_vres fwp_vres_table[FWP_VRES_MAX];
int id;
for (id = 0; id < FWP_VRES_MAX; id++)
- fwp_vres_table[id].status = CLOSED;
+ fwp_vres_table[id].status = FWP_VRES_CLOSED;
}
int fwp_vres_open(struct fwp_contract *cnt)
/* queueing policy should be next parameter*/
{
- int id;
+ int id,rc;
struct fwp_vres *vres;
/* Check for validity of the contract */
/* obtain fwp_vres_table mutex */
/* find free vres */
id = 0;
- while ((id < FWP_VRES_MAX) && (fwp_vres_table[id].status != CLOSED))
+ while ((id < FWP_VRES_MAX) &&
+ (fwp_vres_table[id].status != FWP_VRES_CLOSED)){
+
id++;
+ }
if (id == FWP_VRES_MAX) {
/* release fwp_vres_table mutex */
return -1;
}
+ fprintf(stderr,"id= %d\n",id);
vres = &fwp_vres_table[id];
- vres->status = OPENED;
+ vres->status = FWP_VRES_OPENED;
/* release fwp_vres_table mutex */
memcpy(&vres->contract, cnt, sizeof(struct fwp_contract));
fwp_msgq_init(&vres->tx_queue);
-
- if (fwp_ac_open(vres->contract.ac_id) < 0)
+ if ((rc = fwp_ac_open(vres->contract.ac_id)) < 0) {
return -1;
-
+ }
+ printf("rc = %d \n", rc);
pthread_attr_init(&vres->tx_thread_attr);
- return 0;
-// return pthread_create(&vres->tx_thread, &vres->tx_thread_attr,
-// fwp_vres_tx_thread, (void*) vres);
+ return pthread_create(&vres->tx_thread, &vres->tx_thread_attr,
+ fwp_vres_tx_thread, (void*) vres);
}
int fwp_vres_close(unsigned int id)
{
struct fwp_vres *vres = &fwp_vres_table[id];
- //if ((id < 0)||(id >= MAX_FWP_VRES)||(vres->status != OPENED))
+ //if ((id < 0)||(id >= MAX_FWP_VRES)||(vres->status != FWP_VRES_OPENED))
// return -1;
- vres->status = CLOSED;
+ vres->status = FWP_VRES_CLOSED;
if (fwp_ac_close(vres->contract.ac_id) < 0)
return -1;
-SUBDIRS= fwp_msgtest fwp_prototest unixsocktest
+#SUBDIRS= fwp_msgtest fwp_prototest unixsocktest
+SUBDIRS= fwp_prototest
+#CFLAGS+= -Wall -Wextra
test_PROGRAMS = fwp_sendrecv_test
fwp_sendrecv_test_SOURCES+= fwp_sendrecv_test.c
lib_LOADLIBES += fwp pthread rt
int main()
{
- struct sockaddr_in local_addr, rem_addr, from;
- int sockfd;
- long len;
- unsigned int vres_id1, vres_id2;
- int i;
+ //struct sockaddr_in local_addr, rem_addr, from;
+ //int sockfd;
+ //long len;
+ int vres_id1, vres_id2;
+ //int i;
struct fwp_contract cnt1;
struct fwp_contract cnt2;
- char msg1[] = "Hello1";
- char msg2[] = "Hello2";
- char buffer[30];
- struct fwp_msgb *msgb;
- socklen_t fromlen;
+ //char msg1[] = "Hello1";
+ //char msg2[] = "Hello2";
+ //char buffer[30];
+ //struct fwp_msgb *msgb;
+ //socklen_t fromlen;
cnt1.ac_id = FWP_AC_VO;
cnt1.budget = 100;
cnt2.period_usec = 150;
printf("Start\n");
- fwp_vres_table_init();
- vres_id1 = fwp_vres_open(&cnt1);
- vres_id2 = fwp_vres_open(&cnt2);
- printf("Vres created\n");
+ fwp_init();
+
+ if ((vres_id1 = fwp_vres_open(&cnt1) < 0)) {
+ printf("fw_vres_open - Unable to open vres1\n");
+ return -1;
+ }
+ printf("Vres created vresid1= %d \n",vres_id1);
+
+ if ((vres_id2 = fwp_vres_open(&cnt2)) < 0){
+ fprintf(stderr,"fw_vres_open - Unable to open vres2\n");
+ return -1;
+ }
+ printf("Vres created vresid2= %d \n",vres_id2);
+
#if 0
memset(&local_addr,0, sizeof(local_addr));
if ((sockfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) {