[9451c2]: src / sock-stream.cc Maximize Restore History

Download this file

sock-stream.cc    150 lines (127 with data), 3.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
// Copyright (C) 2010-2013 Olaf Till <i7tiol@t-online.de>
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <octave/oct.h>
#include <errno.h>
#include <oct-stream.h>
#include <oct-prcstrm.h>
static void handle_errno (const std::string msg, const int err_no)
{
std::string err;
switch (err_no)
{
case EINVAL:
err = "EINVAL";
break;
case ENOMEM:
err = "ENOMEM";
break;
case EACCES:
err = "EACCES";
break;
case EAGAIN:
err = "EAGAIN";
break;
case EEXIST:
err = "EEXIST";
break;
case EFAULT:
err = "EFAULT";
break;
case EFBIG:
err = "EFBIG";
break;
case EINTR:
err = "EINTR";
break;
case EISDIR:
err = "EISDIR";
break;
case ELOOP:
err = "ELOOP";
break;
case EMFILE:
err = "EMFILE";
break;
case ENAMETOOLONG:
err = "ENAMETOOLONG";
break;
case ENFILE:
err = "ENFILE";
break;
case ENODEV:
err = "ENODEV";
break;
case ENOENT:
err = "ENOENT";
break;
case ENOSPC:
err = "ENOSPC";
break;
case ENOTDIR:
err = "ENOTDIR";
break;
case ENXIO:
err = "ENXIO";
break;
case EPERM:
err = "EPERM";
break;
case EROFS:
err = "EROFS";
break;
case ETXTBSY:
err = "ETXTBSY";
break;
case EBADF:
err = "EBADF";
break;
case EDEADLK:
err = "EDEADLK";
break;
case ENOLCK:
err = "ENOLCK";
break;
default:
err = "unknown error";
}
error ("%s: %s\n", msg.c_str (), err.c_str ());
}
int socket_to_oct_iostream (int sd)
{
errno = 0;
FILE *fid = fdopen (sd, "rb+");
if (! fid)
{
handle_errno
("could not get C stream from socket descriptor with 'fdopen'",
errno);
return -1;
}
oct_mach_info::float_format flt_fmt =
oct_mach_info::string_to_float_format ("ieee-le");
std::ios::openmode md = std::ios::in | std::ios::out;
octave_stream os =
octave_stdiostream::create ("", fid, md, flt_fmt);
if (! os)
{
error ("could not get Octave stream from C stream");
return -1;
}
octave_stream_list::insert (os);
return sd; // Octave assigns the same number as in 'sd'
}
/*
;;; Local Variables: ***
;;; mode: C++ ***
;;; End: ***
*/