1 /* xbt_peer_t management functions */
3 /* Copyright (c) 2006 Martin Quinson. All rights reserved. */
5 /* This program is free software; you can redistribute it and/or modify it
6 * under the terms of the license (GNU LGPL) which comes with this package. */
8 #include "xbt/sysdep.h"
12 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(peer, xbt, "peer management");
14 /** \brief constructor */
15 xbt_peer_t xbt_peer_new(const char *name, int port)
17 xbt_peer_t res = xbt_new(s_xbt_peer_t, 1);
18 res->name = xbt_strdup(name);
23 xbt_peer_t xbt_peer_copy(xbt_peer_t h)
25 return xbt_peer_new(h->name, h->port);
28 /** \brief constructor. Argument should be of form '(peername):(port)'. */
29 xbt_peer_t xbt_peer_from_string(const char *peerport)
31 xbt_peer_t res = xbt_new(s_xbt_peer_t, 1);
32 char *name = xbt_strdup(peerport);
33 char *port_str = strchr(name, ':');
35 "argument of xbt_peer_from_string should be of form <peername>:<port>, it's '%s'",
40 res->name = xbt_strdup(name); /* it will be shorter now that we cut the port */
41 res->port = atoi(port_str);
46 /** \brief destructor */
47 void xbt_peer_free(xbt_peer_t peer)
56 /** \brief Freeing function for dynars of xbt_peer_t */
57 void xbt_peer_free_voidp(void *d)
59 xbt_peer_free((xbt_peer_t) * (void **) d);