X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=sim%2Fcommon%2Fdv-sockser.c;h=223691cd63e81299756bbb5c2c9923685e8673b6;hb=2951f6c068f961a2ea1de892fc82cf0229af67da;hp=b09d9c94d261fe6feb5456b44c8e61f943aededb;hpb=363a6e9f2c3fe1e25f8fa986347948897f189f39;p=deliverable%2Fbinutils-gdb.git diff --git a/sim/common/dv-sockser.c b/sim/common/dv-sockser.c index b09d9c94d2..223691cd63 100644 --- a/sim/common/dv-sockser.c +++ b/sim/common/dv-sockser.c @@ -1,5 +1,5 @@ /* Serial port emulation using sockets. - Copyright (C) 1998, 2007, 2008, 2009, 2010 Free Software Foundation, Inc. + Copyright (C) 1998-2020 Free Software Foundation, Inc. Contributed by Cygnus Solutions. This program is free software; you can redistribute it and/or modify @@ -18,6 +18,7 @@ along with this program. If not, see . */ /* FIXME: will obviously need to evolve. - connectionless sockets might be more appropriate. */ +#include "config.h" #include "sim-main.h" #ifdef HAVE_STRING_H @@ -174,12 +175,12 @@ dv_sockser_init (SIM_DESC sd) } sockaddr.sin_family = PF_INET; - sockaddr.sin_port = htons(port); + sockaddr.sin_port = htons (port); memcpy (&sockaddr.sin_addr.s_addr, hostent->h_addr, sizeof (struct in_addr)); tmp = 1; - if (setsockopt (sockser_listen_fd, SOL_SOCKET, SO_REUSEADDR, (void*)& tmp, sizeof(tmp)) < 0) + if (setsockopt (sockser_listen_fd, SOL_SOCKET, SO_REUSEADDR, (void*)& tmp, sizeof (tmp)) < 0) { sim_io_eprintf (sd, "sockser init: unable to set SO_REUSEADDR: %s\n", strerror (errno)); @@ -346,13 +347,14 @@ dv_sockser_status (SIM_DESC sd) } int -dv_sockser_write (SIM_DESC sd, unsigned char c) +dv_sockser_write_buffer (SIM_DESC sd, const unsigned char *buffer, + unsigned nr_bytes) { int n; if (! connected_p (sd)) return -1; - n = write (sockser_fd, &c, 1); + n = write (sockser_fd, buffer, nr_bytes); if (n == -1) { if (errno == EPIPE) @@ -362,9 +364,15 @@ dv_sockser_write (SIM_DESC sd, unsigned char c) } return -1; } - if (n != 1) + if (n != nr_bytes) return -1; - return 1; + return nr_bytes; +} + +int +dv_sockser_write (SIM_DESC sd, unsigned char c) +{ + return dv_sockser_write_buffer (sd, &c, 1); } int