Skip to content

Add option to use TCP NODELAY #221

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion source/mysql/connection.d
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,6 @@ package:
// so detect & prevent infinite recursion.
private bool isAutoPurging = false;


/// Called whenever mysql-native needs to send a command to the server
/// and be sure there aren't any pending results (which would prevent
/// a new command from being sent).
Expand Down Expand Up @@ -739,6 +738,16 @@ public:
resetPacket();
}

void tcpNoDelay(bool enabled)
{
_socket.tcpNoDelay(enabled);
}

bool tcpNoDelay()
{
return _socket.tcpNoDelay;
}

/++
Reconnects to the server using the same connection settings originally
used to create the `Connection`.
Expand Down
12 changes: 6 additions & 6 deletions source/mysql/protocol/comms.d
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/++
/++
Internal - Low-level communications.

Consider this module the main entry point for the low-level MySQL/MariaDB
Expand Down Expand Up @@ -45,7 +45,7 @@ package struct ProtocolPrepared
import std.datetime;
import std.variant;
import mysql.types;

static ubyte[] makeBitmap(in Variant[] inParams)
{
size_t bml = (inParams.length+7)/8;
Expand Down Expand Up @@ -451,7 +451,7 @@ package struct ProtocolPrepared
Variant[] inParams, ParameterSpecialization[] psa)
{
conn.autoPurge();

ubyte[] packet;
conn.resetPacket();

Expand Down Expand Up @@ -771,7 +771,7 @@ body
}

conn.autoPurge();

conn.resetPacket();

ubyte[] header;
Expand Down Expand Up @@ -967,7 +967,7 @@ package(mysql) SvrCapFlags setClientFlags(SvrCapFlags serverCaps, SvrCapFlags ca
// didn't supply it
cCaps |= SvrCapFlags.PROTOCOL41;
cCaps |= SvrCapFlags.SECURE_CONNECTION;

return cCaps;
}

Expand Down Expand Up @@ -998,7 +998,7 @@ package(mysql) PreparedServerInfo performRegister(Connection conn, const(char[])
scope(failure) conn.kill();

PreparedServerInfo info;

conn.sendCmd(CommandType.STMT_PREPARE, sql);
conn._fieldCount = 0;

Expand Down
28 changes: 27 additions & 1 deletion source/mysql/protocol/sockets.d
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/// Internal - Phobos and vibe.d sockets.
/// Internal - Phobos and vibe.d sockets.
module mysql.protocol.sockets;

import core.stdc.stdint;

import std.exception;
import std.socket;

Expand Down Expand Up @@ -45,6 +47,8 @@ interface MySQLSocket
void release();
bool isOwner();
bool amOwner();
void tcpNoDelay(bool enabled);
bool tcpNoDelay();
}

/// Wraps a Phobos socket with the common interface
Expand Down Expand Up @@ -100,6 +104,18 @@ class MySQLSocketPhobos : MySQLSocket
void release() { /+ Do nothing +/ }
bool isOwner() { return true; }
bool amOwner() { return true; }

void tcpNoDelay(bool enabled)
{
socket.setOption(SocketOptionLevel.TCP, SocketOption.TCP_NODELAY, cast(int32_t) enabled);
}

bool tcpNoDelay()
{
int32_t result = void;
socket.getOption(SocketOptionLevel.TCP, SocketOption.TCP_NODELAY, result);
return result != 0;
}
}

version(Have_vibe_core) {
Expand Down Expand Up @@ -156,5 +172,15 @@ version(Have_vibe_core) {
bool isOwner() { return true; }
bool amOwner() { return true; }
}

void tcpNoDelay(bool enabled)
{
socket.tcpNoDelay(enabled);
}

bool tcpNoDelay()
{
return socket.tcpNoDelay;
}
}
}