Commit 5a0674df authored by Martin Sustrik's avatar Martin Sustrik

OpenPGM error handling improved

parent 990a1e86
...@@ -17,11 +17,11 @@ ...@@ -17,11 +17,11 @@
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <Python.h>
#include <stddef.h> #include <stddef.h>
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <Python.h>
#include "../c/zmq.h" #include "../c/zmq.h"
......
...@@ -144,9 +144,22 @@ int zmq::pgm_socket_t::open_transport () ...@@ -144,9 +144,22 @@ int zmq::pgm_socket_t::open_transport ()
struct pgm_transport_info_t *res = NULL; struct pgm_transport_info_t *res = NULL;
if (!pgm_if_get_transport_info (network, NULL, &res, &pgm_error)) { if (!pgm_if_get_transport_info (network, NULL, &res, &pgm_error)) {
errno = EINVAL;
g_error_free (pgm_error); if (pgm_error->code == PGM_IF_ERROR_INVAL ||
return -1; pgm_error->code == PGM_IF_ERROR_XDEV ||
pgm_error->code == PGM_IF_ERROR_NODEV ||
pgm_error->code == PGM_IF_ERROR_NOTUNIQ ||
pgm_error->code == PGM_IF_ERROR_ADDRFAMILY ||
pgm_error->code == PGM_IF_ERROR_FAMILY ||
pgm_error->code == PGM_IF_ERROR_NODATA ||
pgm_error->code == PGM_IF_ERROR_NONAME ||
pgm_error->code == PGM_IF_ERROR_SERVICE) {
errno = EINVAL;
g_error_free (pgm_error);
return -1;
}
zmq_assert (false);
} }
res->ti_gsi = gsi; res->ti_gsi = gsi;
...@@ -159,11 +172,16 @@ int zmq::pgm_socket_t::open_transport () ...@@ -159,11 +172,16 @@ int zmq::pgm_socket_t::open_transport ()
} }
if (!pgm_transport_create (&transport, res, &pgm_error)) { if (!pgm_transport_create (&transport, res, &pgm_error)) {
pgm_if_free_transport_info (res); if (pgm_error->code == PGM_TRANSPORT_ERROR_INVAL ||
// TODO: tranlate errors from glib into errnos. pgm_error->code == PGM_TRANSPORT_ERROR_PERM ||
errno = EINVAL; pgm_error->code == PGM_TRANSPORT_ERROR_NODEV) {
g_error_free (pgm_error); pgm_if_free_transport_info (res);
return -1; g_error_free (pgm_error);
errno = EINVAL;
return -1;
}
zmq_assert (false);
} }
pgm_if_free_transport_info (res); pgm_if_free_transport_info (res);
...@@ -316,10 +334,21 @@ int zmq::pgm_socket_t::open_transport () ...@@ -316,10 +334,21 @@ int zmq::pgm_socket_t::open_transport ()
// Bind a transport to the specified network devices. // Bind a transport to the specified network devices.
if (!pgm_transport_bind (transport, &pgm_error)) { if (!pgm_transport_bind (transport, &pgm_error)) {
// TODO: tranlate errors from glib into errnos. if (pgm_error->code == PGM_IF_ERROR_INVAL ||
errno = EINVAL; pgm_error->code == PGM_IF_ERROR_XDEV ||
g_error_free (pgm_error); pgm_error->code == PGM_IF_ERROR_NODEV ||
return -1; pgm_error->code == PGM_IF_ERROR_NOTUNIQ ||
pgm_error->code == PGM_IF_ERROR_ADDRFAMILY ||
pgm_error->code == PGM_IF_ERROR_FAMILY ||
pgm_error->code == PGM_IF_ERROR_NODATA ||
pgm_error->code == PGM_IF_ERROR_NONAME ||
pgm_error->code == PGM_IF_ERROR_SERVICE) {
g_error_free (pgm_error);
errno = EINVAL;
return -1;
}
zmq_assert (false);
} }
return 0; return 0;
...@@ -492,7 +521,11 @@ ssize_t zmq::pgm_socket_t::receive (void **raw_data_, const pgm_tsi_t **tsi_) ...@@ -492,7 +521,11 @@ ssize_t zmq::pgm_socket_t::receive (void **raw_data_, const pgm_tsi_t **tsi_)
const PGMIOStatus status = pgm_recvmsgv (transport, pgm_msgv, const PGMIOStatus status = pgm_recvmsgv (transport, pgm_msgv,
pgm_msgv_len, MSG_DONTWAIT, &nbytes_rec, &pgm_error); pgm_msgv_len, MSG_DONTWAIT, &nbytes_rec, &pgm_error);
if (status == PGM_IO_STATUS_ERROR) {
zmq_assert (false);
}
// In a case when no ODATA/RDATA fired POLLIN event (SPM...) // In a case when no ODATA/RDATA fired POLLIN event (SPM...)
// pgm_recvmsg returns ?. // pgm_recvmsg returns ?.
if (status == PGM_IO_STATUS_TIMER_PENDING) { if (status == PGM_IO_STATUS_TIMER_PENDING) {
...@@ -520,7 +553,6 @@ ssize_t zmq::pgm_socket_t::receive (void **raw_data_, const pgm_tsi_t **tsi_) ...@@ -520,7 +553,6 @@ ssize_t zmq::pgm_socket_t::receive (void **raw_data_, const pgm_tsi_t **tsi_)
return -1; return -1;
} }
// Catch the rest of the errors.
zmq_assert (status == PGM_IO_STATUS_NORMAL); zmq_assert (status == PGM_IO_STATUS_NORMAL);
} }
...@@ -556,6 +588,10 @@ void zmq::pgm_socket_t::process_upstream () ...@@ -556,6 +588,10 @@ void zmq::pgm_socket_t::process_upstream ()
PGMIOStatus status = pgm_recvmsgv (transport, &dummy_msg, PGMIOStatus status = pgm_recvmsgv (transport, &dummy_msg,
1, MSG_DONTWAIT, &dummy_bytes, &pgm_error); 1, MSG_DONTWAIT, &dummy_bytes, &pgm_error);
if (status == PGM_IO_STATUS_ERROR) {
zmq_assert (false);
}
// No data should be returned. // No data should be returned.
zmq_assert (dummy_bytes == 0 && (status == PGM_IO_STATUS_TIMER_PENDING || zmq_assert (dummy_bytes == 0 && (status == PGM_IO_STATUS_TIMER_PENDING ||
status == PGM_IO_STATUS_RATE_LIMITED)); status == PGM_IO_STATUS_RATE_LIMITED));
......
...@@ -50,12 +50,6 @@ namespace zmq ...@@ -50,12 +50,6 @@ namespace zmq
// Initialize PGM network structures (GSI, GSRs). // Initialize PGM network structures (GSI, GSRs).
int init (bool udp_encapsulation_, const char *network_); int init (bool udp_encapsulation_, const char *network_);
// Open PGM transport. Parameters are the same as in constructor.
int open_transport ();
// Close transport.
void close_transport ();
// Get receiver fds and store them into user allocated memory. // Get receiver fds and store them into user allocated memory.
void get_receiver_fds (int *receive_fd_, int *waiting_pipe_fd_); void get_receiver_fds (int *receive_fd_, int *waiting_pipe_fd_);
...@@ -82,6 +76,12 @@ namespace zmq ...@@ -82,6 +76,12 @@ namespace zmq
void process_upstream (); void process_upstream ();
private: private:
// Open PGM transport.
int open_transport ();
// Close transport.
void close_transport ();
// OpenPGM transport // OpenPGM transport
pgm_transport_t* transport; pgm_transport_t* transport;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment