/** Create a new out stream for sending over the network * \param transport string representing the protocol used to establish the connection (oml_strndup()'d locally) * \param hostname string representing the host to connect to (oml_strndup()'d locally) * \param service symbolic name or port number of the service to connect to (oml_strndup()'d locally) * \return a new OmlOutStream instance * * \see oml_strndup */ OmlOutStream* net_stream_new(const char *transport, const char *hostname, const char *service) { MString *dest; assert(transport != NULL && hostname != NULL && service != NULL); OmlNetOutStream* self = (OmlNetOutStream *)oml_malloc(sizeof(OmlNetOutStream)); memset(self, 0, sizeof(OmlNetOutStream)); dest = mstring_create(); mstring_sprintf(dest, "%s://%s:%s", transport, hostname, service); self->dest = (char*)oml_strndup (mstring_buf(dest), mstring_len(dest)); mstring_delete(dest); self->protocol = (char*)oml_strndup (transport, strlen (transport)); self->host = (char*)oml_strndup (hostname, strlen (hostname)); self->service = (char*)oml_strndup (service, strlen (service)); logdebug("%s: Created OmlNetOutStream\n", self->dest); socket_set_non_blocking_mode(0); /* // Now see if we can connect to server */ /* if (! open_socket(self)) { */ /* free(self); */ /* return NULL; */ /* } */ self->write = net_stream_write; self->close = net_stream_close; return (OmlOutStream*)self; }
/** * \fn OmlOutStream* net_stream_new(char* serverURI) * \brief Create a new out stream for sending over the network * \param serverURI URI of communicating peer * \return a new +OmlOutStream+ instance */ OmlOutStream* net_stream_new(const char *transport, const char *hostname, const char *port) { assert(transport != NULL && hostname != NULL && port != NULL); OmlNetOutStream* self = (OmlNetOutStream *)malloc(sizeof(OmlNetOutStream)); memset(self, 0, sizeof(OmlNetOutStream)); // memcpy(&self->storage, serverURI, uriSize); self->protocol = (const char*)xstrndup (transport, strlen (transport)); self->host = (const char*)xstrndup (hostname, strlen (hostname)); self->port = atoi (port); logdebug("Net_stream: connecting to host %s://%s:%d\n", self->protocol, self->host, self->port); socket_set_non_blocking_mode(0); /* // Now see if we can connect to server */ /* if (! open_socket(self)) { */ /* free(self); */ /* return NULL; */ /* } */ self->write = net_stream_write; self->close = net_stream_close; return (OmlOutStream*)self; }