Switch to unified view

a/src/utils/netcon.h b/src/utils/netcon.h
...
...
213
};
213
};
214
214
215
/// Base class for connections that actually transfer data. T
215
/// Base class for connections that actually transfer data. T
216
class NetconData : public Netcon {
216
class NetconData : public Netcon {
217
public:
217
public:
218
    NetconData() : m_buf(0), m_bufbase(0), m_bufbytes(0), m_bufsize(0) {
218
    NetconData(bool cancellable = false);
219
    }
220
    virtual ~NetconData();
219
    virtual ~NetconData();
221
220
222
    /// Write data to the connection.
221
    /// Write data to the connection.
223
    /// @param buf the data buffer
222
    /// @param buf the data buffer
224
    /// @param cnt the number of bytes we should try to send
223
    /// @param cnt the number of bytes we should try to send
...
...
230
    /// Read from the connection
229
    /// Read from the connection
231
    /// @param buf the data buffer
230
    /// @param buf the data buffer
232
    /// @param cnt the number of bytes we should try to read (but we return
231
    /// @param cnt the number of bytes we should try to read (but we return
233
    ///   as soon as we get data)
232
    ///   as soon as we get data)
234
    /// @param timeo maximum number of seconds we should be waiting for data.
233
    /// @param timeo maximum number of seconds we should be waiting for data.
235
    /// @return the count of bytes actually read. 0 for timeout (call
234
    /// @return the count of bytes actually read (0 for EOF), or
236
    ///        didtimo() to discriminate from EOF). -1 if an error occurred.
235
    ///    TimeoutOrError (-1) for timeout or error (call timedout() to
236
    ///    discriminate and reset), Cancelled (-2) if cancelled.
237
    enum RcvReason {Eof = 0, TimeoutOrError = -1, Cancelled = -2};
237
    virtual int receive(char *buf, int cnt, int timeo = -1);
238
    virtual int receive(char *buf, int cnt, int timeo = -1);
239
    virtual void cancelReceive();
240
238
    /// Loop on receive until cnt bytes are actually read or a timeout occurs
241
    /// Loop on receive until cnt bytes are actually read or a timeout occurs
239
    virtual int doreceive(char *buf, int cnt, int timeo = -1);
242
    virtual int doreceive(char *buf, int cnt, int timeo = -1);
240
    /// Check for data being available for reading
243
241
    virtual int readready();
242
    /// Check for data being available for writing
243
    virtual int writeready();
244
    /// Read a line of text on an ascii connection. Returns -1 or byte count
244
    /// Read a line of text on an ascii connection. Returns -1 or byte count
245
    /// including final 0. \n is kept
245
    /// including final 0. \n is kept
246
    virtual int getline(char *buf, int cnt, int timeo = -1);
246
    virtual int getline(char *buf, int cnt, int timeo = -1);
247
247
    /// Set handler to be called when the connection is placed in the
248
    /// Set handler to be called when the connection is placed in the
248
    /// selectloop and an event occurs.
249
    /// selectloop and an event occurs.
249
    virtual void setcallback(std::shared_ptr<NetconWorker> user) {
250
    virtual void setcallback(std::shared_ptr<NetconWorker> user) {
250
        m_user = user;
251
        m_user = user;
251
    }
252
    }
252
253
253
private:
254
private:
255
254
    char *m_buf;    // Buffer. Only used when doing getline()s
256
    char *m_buf;    // Buffer. Only used when doing getline()s
255
    char *m_bufbase;    // Pointer to current 1st byte of useful data
257
    char *m_bufbase;    // Pointer to current 1st byte of useful data
256
    int m_bufbytes; // Bytes of data.
258
    int m_bufbytes; // Bytes of data.
257
    int m_bufsize;  // Total buffer size
259
    int m_bufsize;  // Total buffer size
260
261
    int m_wkfds[2];
262
    
258
    std::shared_ptr<NetconWorker> m_user;
263
    std::shared_ptr<NetconWorker> m_user;
259
    virtual int cando(Netcon::Event reason); // Selectloop slot
264
    virtual int cando(Netcon::Event reason); // Selectloop slot
260
};
265
};
261
266
262
/// Network endpoint, client side.
267
/// Network endpoint, client side.
263
class NetconCli : public NetconData {
268
class NetconCli : public NetconData {
264
public:
269
public:
265
    NetconCli(int silent = 0) {
270
    NetconCli(bool cancellable = false)
266
        m_silentconnectfailure = silent;
271
        : NetconData(cancellable), m_silentconnectfailure(false) {
267
    }
272
    }
268
273
269
    /// Open connection to specified host and named service. Set host
274
    /// Open connection to specified host and named service. Set host
270
    /// to an absolute path name for an AF_UNIX service. serv is
275
    /// to an absolute path name for an AF_UNIX service. serv is
271
    /// ignored in this case.
276
    /// ignored in this case.
...
...
282
    /// setconn(-1) if you need to really close the fd and have no
287
    /// setconn(-1) if you need to really close the fd and have no
283
    /// other copy).
288
    /// other copy).
284
    int setconn(int fd);
289
    int setconn(int fd);
285
290
286
    /// Do not log message if openconn() fails.
291
    /// Do not log message if openconn() fails.
287
    void setSilentFail(int onoff) {
292
    void setSilentFail(bool onoff) {
288
        m_silentconnectfailure = onoff;
293
        m_silentconnectfailure = onoff;
289
    }
294
    }
290
295
291
private:
296
private:
292
    int m_silentconnectfailure; // No logging of connection failures if set
297
    bool m_silentconnectfailure; // No logging of connection failures if set
293
};
298
};
294
299
295
class NetconServCon;
300
class NetconServCon;
296
#ifdef NETCON_ACCESSCONTROL
301
#ifdef NETCON_ACCESSCONTROL
297
struct intarrayparam {
302
struct intarrayparam {