1 /* xbt_peer_t management functions */
3 /* Copyright (c) 2006-2014. 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 /** \brief copy constructor */
25 xbt_peer_t xbt_peer_copy(xbt_peer_t h)
27 return xbt_peer_new(h->name, h->port);
30 /** \brief constructor. Argument should be of form '(peername):(port)'. */
31 xbt_peer_t xbt_peer_from_string(const char *peerport)
33 xbt_peer_t res = xbt_new(s_xbt_peer_t, 1);
34 char *name = xbt_strdup(peerport);
35 char *port_str = strchr(name, ':');
37 "argument of xbt_peer_from_string should be of form <peername>:<port>, it's '%s'",
42 res->name = xbt_strdup(name); /* it will be shorter now that we cut the port */
43 res->port = atoi(port_str);
48 /** \brief destructor */
49 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);