/* $Id$ */
-/* gras_rl - implementation of GRAS on top of the SimGrid simulator */
+/* gras_sg - legacy implementation of GRAS on top of the SimGrid simulator */
+/* This file should be KILLED whenever the raw sockets work in the new gras */
-/* Authors: Martin Quinson */
-/* Copyright (C) 2003 the OURAGAN project. */
+/* Copyright (c) 2003 Martin Quinson. All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
- under the terms of the license (GNU LGPL) which comes with this package. */
+ * under the terms of the license (GNU LGPL) which comes with this package. */
#include <stdio.h>
#include <string.h>
#include "gras_sg.h"
-GRAS_LOG_DEFAULT_CATEGORY(GRAS);
+XBT_LOG_DEFAULT_CATEGORY(GRAS);
-gras_error_t
-gras_process_init() {
- gras_hostdata_t *hd=(gras_hostdata_t *)MSG_host_get_data(MSG_host_self());
- grasProcessData_t *pd;
- int i;
-
- if (!(pd=(grasProcessData_t *)malloc(sizeof(grasProcessData_t)))) {
- fprintf(stderr,"grasInit: out of memory\n");
- return malloc_error;
- }
- pd->grasMsgQueueLen=0;
- pd->grasMsgQueue = NULL;
-
- pd->grasCblListLen = 0;
- pd->grasCblList = NULL;
-
- if (MSG_process_set_data(MSG_process_self(),(void*)pd) != MSG_OK) {
- return unknown_error;
- }
-
- if (!hd) {
- if (!(hd=(gras_hostdata_t *)malloc(sizeof(gras_hostdata_t)))) {
- fprintf(stderr,"grasInit: out of memory\n");
- return malloc_error;
- }
- hd->portLen = 0;
- hd->port=NULL;
- hd->port2chan=NULL;
- for (i=0; i<MAX_CHANNEL; i++) {
- hd->proc[i]=0;
- }
-
- if (MSG_host_set_data(MSG_host_self(),(void*)hd) != MSG_OK) {
- return unknown_error;
- }
- }
-
- /* take a free channel for this process */
- for (i=0; i<MAX_CHANNEL && hd->proc[i]; i++);
- if (i == MAX_CHANNEL) {
- fprintf(stderr,
- "GRAS: Can't add a new process on %s, because all channel are already in use. Please increase MAX CHANNEL (which is %d for now) and recompile GRAS\n.",
- MSG_host_get_name(MSG_host_self()),MAX_CHANNEL);
- return system_error;
- }
- pd->chan = i;
- hd->proc[ i ] = MSG_process_self_PID();
-
- /* take a free channel for this process */
- for (i=0; i<MAX_CHANNEL && hd->proc[i]; i++);
- if (i == MAX_CHANNEL) {
- fprintf(stderr,
- "GRAS: Can't add a new process on %s, because all channel are already in use. Please increase MAX CHANNEL (which is %d for now) and recompile GRAS\n.",
- MSG_host_get_name(MSG_host_self()),MAX_CHANNEL);
- return system_error;
- }
- pd->rawChan = i;
- hd->proc[ i ] = MSG_process_self_PID();
-
- /*
- fprintf(stderr,"GRAS: Creating process '%s' (%d)\n",
- MSG_process_get_name(MSG_process_self()),MSG_process_self_PID());
- */
- return no_error;
-}
-
-gras_error_t
-gras_process_finalize() {
- gras_hostdata_t *hd=(gras_hostdata_t *)MSG_host_get_data(MSG_host_self());
- grasProcessData_t *pd=(grasProcessData_t *)MSG_process_get_data(MSG_process_self());
- int myPID=MSG_process_self_PID();
- int i;
-
- gras_assert0(hd && pd,"Run gras_process_init!!\n");
-
-
- fprintf(stderr,"GRAS: Finalizing process '%s' (%d)\n",
- MSG_process_get_name(MSG_process_self()),MSG_process_self_PID());
- if (pd->grasMsgQueueLen) {
- fprintf(stderr,"GRAS: Warning: process %d terminated, but some queued messages where not handled\n",MSG_process_self_PID());
- }
-
- for (i=0; i< MAX_CHANNEL; i++)
- if (myPID == hd->proc[i])
- hd->proc[i] = 0;
-
- for (i=0; i<hd->portLen; i++) {
- if (hd->port2chan[ i ] == pd->chan) {
- memmove(&(hd->port[i]), &(hd->port[i+1]), (hd->portLen -i -1) * sizeof(int));
- memmove(&(hd->port2chan[i]), &(hd->port2chan[i+1]), (hd->portLen -i -1) * sizeof(int));
- hd->portLen--;
- i--; /* counter the effect of the i++ at the end of the iteration */
- }
- }
-
- return no_error;
-}
/* **************************************************************************
* Openning/Maintaining/Closing connexions (private functions for both raw
* and regular sockets)
* **************************************************************************/
-gras_error_t
+xbt_error_t
_gras_sock_server_open(unsigned short startingPort, unsigned short endingPort,
int raw, unsigned int bufSize, /* OUT */ gras_sock_t **sock) {
int port,i;
const char *host=MSG_host_get_name(MSG_host_self());
- gras_assert0(hd,"HostData=NULL !! Please run grasInit on each process\n");
- gras_assert0(pd,"ProcessData=NULL !! Please run grasInit on each process\n");
+ xbt_assert0(hd,"HostData=NULL !! Please run grasInit on each process\n");
+ xbt_assert0(pd,"ProcessData=NULL !! Please run grasInit on each process\n");
for (port=startingPort ; port <= endingPort ; port++) {
for (i=0; i<hd->portLen && hd->port[i] != port; i++);
return mismatch_error;
}
-gras_error_t
+xbt_error_t
_gras_sock_client_open(const char *host, short port, int raw, unsigned int bufSize,
/* OUT */ gras_sock_t **sock) {
m_host_t peer;
return no_error;
}
-gras_error_t _gras_sock_close(int raw, gras_sock_t *sd) {
+xbt_error_t _gras_sock_close(int raw, gras_sock_t *sd) {
gras_hostdata_t *hd=(gras_hostdata_t *)MSG_host_get_data(MSG_host_self());
int i;
- gras_assert0(hd,"HostData=NULL !! Please run grasInit on each process\n");
+ xbt_assert0(hd,"HostData=NULL !! Please run grasInit on each process\n");
if (!sd) return no_error;
if (raw && !sd->raw_sock) {
/* **************************************************************************
* Creating/Using regular sockets
* **************************************************************************/
-gras_error_t
+xbt_error_t
gras_sock_server_open(unsigned short startingPort, unsigned short endingPort,
/* OUT */ gras_sock_t **sock) {
return _gras_sock_server_open(startingPort,endingPort,0,0,sock);
}
-gras_error_t
+xbt_error_t
gras_sock_client_open(const char *host, short port,
/* OUT */ gras_sock_t **sock) {
return _gras_sock_client_open(host,port,0,0,sock);
}
-gras_error_t gras_sock_close(gras_sock_t *sd) {
+xbt_error_t gras_sock_close(gras_sock_t *sd) {
return _gras_sock_close(0,sd);
}
/* **************************************************************************
* Creating/Using raw sockets
* **************************************************************************/
-gras_error_t gras_rawsock_server_open(unsigned short startingPort, unsigned short endingPort,
+xbt_error_t gras_rawsock_server_open(unsigned short startingPort, unsigned short endingPort,
unsigned int bufSize, gras_rawsock_t **sock) {
return _gras_sock_server_open(startingPort,endingPort,1,bufSize,(gras_sock_t**)sock);
}
-gras_error_t gras_rawsock_client_open(const char *host, short port,
+xbt_error_t gras_rawsock_client_open(const char *host, short port,
unsigned int bufSize, gras_rawsock_t **sock) {
return _gras_sock_client_open(host,port,1,bufSize,(gras_sock_t**)sock);
}
-gras_error_t gras_rawsock_close(gras_rawsock_t *sd) {
+xbt_error_t gras_rawsock_close(gras_rawsock_t *sd) {
return _gras_sock_close(1,(gras_sock_t*)sd);
}
return sd->to_port;
}
-gras_error_t
+xbt_error_t
gras_rawsock_send(gras_rawsock_t *sock, unsigned int expSize, unsigned int msgSize) {
unsigned int bytesTotal;
static unsigned int count=0;
m_task_t task=NULL;
char name[256];
- gras_assert0(sock->raw_sock,"Asked to send raw data on a regular socket\n");
+ xbt_assert0(sock->raw_sock,"Asked to send raw data on a regular socket\n");
for(bytesTotal = 0;
bytesTotal < expSize;
return no_error;
}
-gras_error_t
+xbt_error_t
gras_rawsock_recv(gras_rawsock_t *sock, unsigned int expSize, unsigned int msgSize,
unsigned int timeout) {
grasProcessData_t *pd=(grasProcessData_t *)MSG_process_get_data(MSG_process_self());
m_task_t task=NULL;
double startTime;
- gras_assert0(sock->raw_sock,"Asked to receive raw data on a regular socket\n");
+ xbt_assert0(sock->raw_sock,"Asked to receive raw data on a regular socket\n");
startTime=gras_time();
for(bytesTotal = 0;
* Actually exchanging messages
* **************************************************************************/
-gras_error_t
+xbt_error_t
grasMsgRecv(gras_msg_t **msg,
double timeOut) {
return timeout_error;
}
-gras_error_t
+xbt_error_t
gras_msg_send(gras_sock_t *sd,
gras_msg_t *_msg,
- e_gras_free_directive_t freeDirective) {
+ e_xbt_free_directive_t freeDirective) {
grasProcessData_t *pd=grasProcessDataGet();
m_task_t task;
gras_sock_t *answer;
/* arg validity checks */
- gras_assert0(msg,"Trying to send NULL message");
- gras_assert0(sd ,"Trying to send over a NULL socket");
+ xbt_assert0(msg,"Trying to send NULL message");
+ xbt_assert0(sd ,"Trying to send over a NULL socket");
if (!(answer=(gras_sock_t*)malloc(sizeof(gras_sock_t)))) {
RAISE_MALLOC;