Permalink
Browse files

protocols: Allocate I/O fdbuf objects in protocol wrapper

  • Loading branch information...
1 parent 245971b commit 3539a0e83a2307b2d60b1c10cbd50c5930b6719e @bruceg committed Apr 16, 2012
Showing with 20 additions and 16 deletions.
  1. +5 −1 protocols/protocol.cc
  2. +1 −1 protocols/protocol.h
  3. +7 −7 protocols/qmqp.cc
  4. +7 −7 protocols/smtp.cc
View
@@ -71,7 +71,11 @@ int cli_main(int, char* argv[])
int fd = tcpconnect(remote, port);
if(fd < 0)
protocol_fail(-fd, "Connect failed");
- protocol_send(in, fd);
+ fdibuf netin(fd);
+ fdobuf netout(fd);
+ if (!netin || !netout)
+ protocol_fail(ERR_MSG_TEMPFAIL, "Error allocating I/O buffers");
+ protocol_send(in, netin, netout);
return 0;
}
View
@@ -16,6 +16,6 @@ extern int auth_method;
extern int port;
extern void protocol_prep(fdibuf& in);
-extern void protocol_send(fdibuf& in, int fd);
+extern void protocol_send(fdibuf& in, fdibuf& netin, fdobuf& netout);
#endif
View
@@ -36,16 +36,16 @@ const char* cli_help_prefix = "Send an emal message via QMQP\n";
class qmqp
{
- fdibuf in;
- fdobuf out;
+ fdibuf& in;
+ fdobuf& out;
public:
- qmqp(int fd);
+ qmqp(fdibuf& netin, fdobuf& netout);
~qmqp();
void send(fdibuf& msg, unsigned long size, const mystring& env);
};
-qmqp::qmqp(int fd)
- : in(fd), out(fd)
+qmqp::qmqp(fdibuf& netin, fdobuf& netout)
+ : in(netin), out(netout)
{
}
@@ -125,9 +125,9 @@ void protocol_prep(fdibuf& in)
protocol_fail(ERR_MSG_READ, "Error reading message");
}
-void protocol_send(fdibuf& in, int fd)
+void protocol_send(fdibuf& in, fdibuf& netin, fdobuf& netout)
{
alarm(60*60); // Connection must close after an hour
- qmqp conn(fd);
+ qmqp conn(netin, netout);
conn.send(in, msg_size, msg_envelope);
}
View
@@ -36,11 +36,11 @@ const char* cli_help_prefix = "Send an email message via SMTP\n";
class smtp
{
- fdibuf in;
- fdobuf out;
+ fdibuf& in;
+ fdobuf& out;
mystring caps;
public:
- smtp(int fd);
+ smtp(fdibuf& netin, fdobuf& netout);
~smtp();
int get(mystring& str);
int put(mystring cmd, mystring& result);
@@ -55,8 +55,8 @@ class smtp
void send(fdibuf& msg);
};
-smtp::smtp(int fd)
- : in(fd), out(fd)
+smtp::smtp(fdibuf& netin, fdobuf& netout)
+ : in(netin), out(netout)
{
}
@@ -211,9 +211,9 @@ void protocol_prep(fdibuf&)
{
}
-void protocol_send(fdibuf& in, int fd)
+void protocol_send(fdibuf& in, fdibuf& netin, fdobuf& netout)
{
- smtp conn(fd);
+ smtp conn(netin, netout);
conn.docmd("", 200);
if (user != 0 && pass != 0) {

0 comments on commit 3539a0e

Please sign in to comment.