1 /* xbt_peer_t management functions */
3 /* Copyright (c) 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
9 #include "xbt/sysdep.h"
13 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(peer, xbt, "peer management");
15 /** \brief constructor */
16 xbt_peer_t xbt_peer_new(const char *name, int port)
18 xbt_peer_t res = xbt_new(s_xbt_peer_t, 1);
19 res->name = xbt_strdup(name);
24 xbt_peer_t xbt_peer_copy(xbt_peer_t h)
26 return xbt_peer_new(h->name, h->port);
29 /** \brief constructor. Argument should be of form '(peername):(port)'. */
30 xbt_peer_t xbt_peer_from_string(const char *peerport)
32 xbt_peer_t res = xbt_new(s_xbt_peer_t, 1);
33 char *name = xbt_strdup(peerport);
34 char *port_str = strchr(name, ':');
36 "argument of xbt_peer_from_string should be of form <peername>:<port>, it's '%s'",
41 res->name = xbt_strdup(name); /* it will be shorter now that we cut the port */
42 res->port = atoi(port_str);
47 /** \brief destructor */
48 void xbt_peer_free(xbt_peer_t peer)
57 /** \brief Freeing function for dynars of xbt_peer_t */
58 void xbt_peer_free_voidp(void *d)
60 xbt_peer_free((xbt_peer_t) * (void **) d);