+void sk_out_assign(struct sk_out *sk_out)
+{
+ if (!sk_out)
+ return;
+
+ sk_lock(sk_out);
+ sk_out->refs++;
+ sk_unlock(sk_out);
+ pthread_setspecific(sk_out_key, sk_out);
+}
+
+static void sk_out_free(struct sk_out *sk_out)
+{
+ fio_mutex_remove(sk_out->lock);
+ fio_mutex_remove(sk_out->wait);
+ sfree(sk_out);
+}
+
+static int __sk_out_drop(struct sk_out *sk_out)
+{
+ if (sk_out) {
+ int refs;
+
+ sk_lock(sk_out);
+ refs = --sk_out->refs;
+ sk_unlock(sk_out);
+
+ if (!refs) {
+ sk_out_free(sk_out);
+ return 0;
+ }
+ }
+
+ return 1;
+}
+
+void sk_out_drop(void)
+{
+ struct sk_out *sk_out;
+
+ sk_out = pthread_getspecific(sk_out_key);
+ if (!__sk_out_drop(sk_out))
+ pthread_setspecific(sk_out_key, NULL);
+}
+
+static void __fio_init_net_cmd(struct fio_net_cmd *cmd, uint16_t opcode,
+ uint32_t pdu_len, uint64_t tag)
+{
+ memset(cmd, 0, sizeof(*cmd));
+
+ cmd->version = __cpu_to_le16(FIO_SERVER_VER);
+ cmd->opcode = cpu_to_le16(opcode);
+ cmd->tag = cpu_to_le64(tag);
+ cmd->pdu_len = cpu_to_le32(pdu_len);
+}
+
+
+static void fio_init_net_cmd(struct fio_net_cmd *cmd, uint16_t opcode,
+ const void *pdu, uint32_t pdu_len, uint64_t tag)
+{
+ __fio_init_net_cmd(cmd, opcode, pdu_len, tag);
+
+ if (pdu)
+ memcpy(&cmd->payload, pdu, pdu_len);
+}
+