Commit 187d7f8c authored by 's avatar
Browse files

Beta fix bug #451

git-svn-id: file:///home/svn/mapi/trunk@908 8d5bb341-7cf1-0310-8cf6-ba355fef3186
parent 450d3ff2
......@@ -503,6 +503,7 @@ int mapi_create_flow(const char *dev)
local_err = MAPI_DEVICE_INFO_ERR;
return -1;
}
#ifdef DIMAPI
remote_flowdescr_t *rflow;
char *hostname=NULL, *s=NULL, *k=NULL;
......@@ -655,13 +656,18 @@ int mapi_create_flow(const char *dev)
}
#endif
pthread_spin_lock(&mapi_lock);
if ((get_numflows() == 0) && (get_totalflows() > 0) && minit) { // socket has been closed, re-create it
pthread_spin_lock(&mapi_lock);
if(mapiipc_client_init()==-1){
local_err = MCOM_INIT_SOCKET_ERROR;
}
pthread_spin_unlock(&mapi_lock);
incr_numflows();
}
else
incr_numflows();
pthread_spin_unlock(&mapi_lock);
qbuf.mtype=1;
qbuf.cmd=CREATE_FLOW;
......@@ -672,11 +678,13 @@ int mapi_create_flow(const char *dev)
if (mapiipc_write((struct mapiipcbuf*)&qbuf)<0) {
local_err = MCOM_SOCKET_ERROR;
pthread_spin_unlock(&mapi_lock);
decr_numflows();
return -1;
}
if (mapiipc_read((struct mapiipcbuf*)&qbuf)<0) {
local_err = MCOM_SOCKET_ERROR;
pthread_spin_unlock(&mapi_lock);
decr_numflows();
return -1;
}
pthread_spin_unlock(&mapi_lock);
......@@ -689,12 +697,14 @@ int mapi_create_flow(const char *dev)
ERROR_CMD(printf("mapid gave us a fd which already exist in our lists (%d), exiting [%s:%d]\n",
qbuf.fd,__FILE__,__LINE__));
//exit(EXIT_FAILURE);
decr_numflows();
return -1;
}
flow=malloc(sizeof(flowdescr_t));
if( flow == NULL ){
fputs( "Out of memory\n", stderr );
//exit( EXIT_FAILURE );
decr_numflows();
return -1;
}
flow->fd=qbuf.fd;
......@@ -710,16 +720,18 @@ int mapi_create_flow(const char *dev)
strcpy(flow->devtype,(char *)qbuf.data);
pthread_spin_lock(&mapi_lock);
flist_append(flowlist,qbuf.fd,flow);
incr_numflows();
//incr_numflows();
incr_totalflows();
pthread_spin_unlock(&mapi_lock);
return qbuf.fd;
/* should probably have a separate error message for ERROR_ACK? */
case ERROR_ACK:
decr_numflows();
local_err=qbuf.remote_errorcode;
return -1;
default:
decr_numflows();
local_err=MCOM_UNKNOWN_ERROR;
return -1;
}
......@@ -752,7 +764,11 @@ int mapi_create_offline_flow(const char *dev, int format)
pthread_spin_unlock(&mapi_lock);
return -1;
}
incr_numflows();
}
else
incr_numflows();
pthread_spin_unlock(&mapi_lock);
qbuf.mtype=1;
......@@ -765,28 +781,33 @@ int mapi_create_offline_flow(const char *dev, int format)
if (mapiipc_write((struct mapiipcbuf*)&qbuf)<0) {
pthread_spin_unlock(&mapi_lock);
local_err = MCOM_SOCKET_ERROR;
decr_numflows();
return -1;
}
if (mapiipc_read((struct mapiipcbuf*)&qbuf)<0) {
pthread_spin_unlock(&mapi_lock);
local_err = MCOM_SOCKET_ERROR;
decr_numflows();
return -1;
}
if(qbuf.cmd==SEND_FD) {
if(mapiipc_send_fd(file)==-1) {
local_err=MAPI_ERROR_SEND_FD;
pthread_spin_unlock(&mapi_lock);
decr_numflows();
return -1;
}
} else {
local_err=MAPI_ERROR_SEND_FD;
pthread_spin_unlock(&mapi_lock);
pthread_spin_unlock(&mapi_lock);
decr_numflows();
return -1;
}
if (mapiipc_read((struct mapiipcbuf*)&qbuf)<0) {
pthread_spin_unlock(&mapi_lock);
local_err = MCOM_SOCKET_ERROR;
decr_numflows();
return -1;
}
pthread_spin_unlock(&mapi_lock);
......@@ -807,15 +828,17 @@ int mapi_create_offline_flow(const char *dev, int format)
strcpy(flow->devtype,(char *)qbuf.data);
pthread_spin_lock(&mapi_lock);
flist_append(flowlist,qbuf.fd,flow);
incr_numflows();
//incr_numflows();
incr_totalflows();
pthread_spin_unlock(&mapi_lock);
return qbuf.fd;
case ERROR_ACK:
local_err=qbuf.remote_errorcode;
decr_numflows();
return -1;
default:
local_err=MCOM_UNKNOWN_ERROR;
decr_numflows();
return -1;
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment