diff --git a/cmd/client/main.go b/cmd/client/main.go index 5dabacc..aab7838 100644 --- a/cmd/client/main.go +++ b/cmd/client/main.go @@ -1,12 +1,14 @@ package main import ( + "fmt" "io" "net" "os" "github.com/spf13/cobra" "github.com/yezzey-gp/yproxy/config" + "github.com/yezzey-gp/yproxy/pkg/client" "github.com/yezzey-gp/yproxy/pkg/proc" "github.com/yezzey-gp/yproxy/pkg/ylogger" ) @@ -75,6 +77,9 @@ var putCmd = &cobra.Command{ return err } + ycl := client.NewYClient(con) + r := proc.NewProtoReader(ycl) + defer con.Close() msg := proc.NewPutMessage(args[0], encrypt).Encode() _, err = con.Write(msg) @@ -120,6 +125,19 @@ var putCmd = &cobra.Command{ return err } + tp, _, err := r.ReadPacket() + if err != nil { + return err + } + + if tp == proc.MessageTypeReadyForQuery { + // ok + + ylogger.Zero.Debug().Msg("got rfq") + } else { + return fmt.Errorf("failed to get rfq") + } + return nil }, } diff --git a/pkg/proc/interaction.go b/pkg/proc/interaction.go index 77d9dcb..917a4a4 100644 --- a/pkg/proc/interaction.go +++ b/pkg/proc/interaction.go @@ -45,6 +45,8 @@ func ProcConn(s storage.StorageInteractor, cr crypt.Crypter, ycl *client.YClient } io.Copy(ycl.Conn, r) + _ = ycl.Conn.Close() + case MessageTypePut: msg := PutMessage{} @@ -106,6 +108,14 @@ func ProcConn(s storage.StorageInteractor, cr crypt.Crypter, ycl *client.YClient return ycl.Conn.Close() } + _, err = ycl.Conn.Write(NewReadyForQueryMessage().Encode()) + + if err != nil { + _ = ycl.ReplyError(err, "failed to upload") + + return ycl.Conn.Close() + } + default: _ = ycl.ReplyError(nil, "wrong request type")